aboutsummaryrefslogtreecommitdiff
path: root/_make
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-04-19 19:46:08 +0200
committerJonas Smedegaard <dr@jones.dk>2025-04-19 19:46:08 +0200
commitebeb0cadb7791ab80a4151bdf966c147ea7e9bb3 (patch)
tree04e4bbb53821a4c091ad41ed7188ea24a2625167 /_make
parent502b4dfe9eacd3559f7ee1e98e6e018f8a206b38 (diff)
add Makefile, with make snippets for hedgedoc and quarto
Diffstat (limited to '_make')
-rw-r--r--_make/hedgedoc.mk52
-rw-r--r--_make/quarto.mk44
2 files changed, 96 insertions, 0 deletions
diff --git a/_make/hedgedoc.mk b/_make/hedgedoc.mk
new file mode 100644
index 0000000..88c8936
--- /dev/null
+++ b/_make/hedgedoc.mk
@@ -0,0 +1,52 @@
+# Make snippet for exchanging data with a HedgeDoc pad
+#
+# Copyright 2024, Jonas Smedegaard <dr@jones.dk>
+# SPDX-License-Identifier: GPL-3+
+#
+# Setup:
+# in main Makefile...
+# * set variable PAD_LIST
+# * set variable PAD_REPLACE if supported and wanted
+# * include this make snippet
+#
+# Dependencies:
+# * hedgedoc <https://github.com/hedgedoc/cli>
+# * perl v5.36 or newer
+
+# whitespace-delimited list of file-URI pairs,
+# each consisting of a relative path to a local file
+# and a relative URI to a HedgeDoc pad,
+# separated by a colon
+#PAD_LIST = \
+# README.md:Xg5jgtkWQNqRzobI0qwrtw \
+# our_project/subdir/foo.data:XxgHj9yCQ_e6bsETro5DMA
+
+# when set to a non-empty value (and HedgeDoc service supports it),
+# importing from local file will attempt to replace existing pad,
+# instead of creating a new pad
+#PAD_REPLACE = yes
+
+# resolve files and URIs from PAD_LIST
+_PADFILES = $(foreach i,$(PAD_LIST),$(firstword $(subst :,$() ,$i)))
+_padfile2uri = $(patsubst $1:%,%,$(filter $1:%,$(PAD_LIST)))
+
+# register with HedgeDoc service
+pad-login:
+ hedgedoc login --email
+
+# list available pads at HedgeDoc service
+pad-list:
+ hedgedoc history
+
+pad-export-all: $(_PADFILES:%=pad-export-to-%)
+
+# export from pad to local file, and ensure it ends with a newline
+$(_PADFILES:%=pad-export-to-%): pad-export-to-%:
+ $(if $(wildcard $(dir $*)),,mkdir --parents $(dir $*))
+ hedgedoc export --md $(call _padfile2uri,$*) $*
+ perl -gpi -e 's/\s*\z/\n/' $*
+
+$(_PADFILES:%=pad-import-from-%): pad-import-from-%: %
+ hedgedoc import $< $(if $(PAD_WANTED),$(call _padfile2uri,$*))
+
+.PHONY: pad-login pad-list pad-export-all $(_PADFILES:%=pad-export-to-%) $(_PADFILES:%=pad-import-from-%)
diff --git a/_make/quarto.mk b/_make/quarto.mk
new file mode 100644
index 0000000..1bea475
--- /dev/null
+++ b/_make/quarto.mk
@@ -0,0 +1,44 @@
+# Make snippet for rendering Quarto documents
+#
+# Copyright 2024, Jonas Smedegaard <dr@jones.dk>
+# SPDX-License-Identifier: GPL-3+
+#
+# Setup:
+# In main Makefile...
+# * set variable DOCUMENTS
+# * set variable DOCUMENT_APPENDIX_REGEX if needed
+# * include this make snippet
+#
+# Dependencies:
+# * quarto <https://quarto.org/>
+# * bat <https://github.com/sharkdp/bat>, with executable named "batcat"
+# * perl v5.10.1 or newer
+
+# list of relative paths to directories,
+# each containing an index.qmd file.
+#DOCUMENTS = \
+# main_paper \
+# promo_article \
+# research/deep/superconductors
+# research/deep/fringe
+
+# regular expression anchored at the beginning of a single line,
+# to match the beginning of content in document to omit from counting
+DOCUMENT_APPENDIX_REGEX ?= Appendix\\b
+
+$(DOCUMENTS:%=doc-render-%): doc-render-%: %.qmd
+ quarto render $<
+
+$(DOCUMENTS:%=doc-screening-of-%): doc-screening-of-%: %.qmd
+ QUARTO_LOG_LEVEL=quiet \
+ quarto render $< --to markdown --output - | batcat --file-name index.qmd --language markdown
+
+# count all characters except horisontal rulers,
+# until appendices
+$(DOCUMENTS:%=doc-charcount-of-%): doc-charcount-of-%: %.qmd
+ QUARTO_LOG_LEVEL=quiet \
+ quarto render $< --to plain --columns=9999 --output - \
+ | perl -nsE 'next if /^-*$$/; $$done += /^$$re/; $$chars += length unless $$done; END { say $$chars }' \
+ -- -re="$(DOCUMENT_APPENDIX_REGEX)"
+
+.PHONY: $(DOCUMENTS:%=doc-render-%) $(DOCUMENTS:%=doc-screening-of-%) $(DOCUMENTS:%=doc-charcount-of-%)