summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--_make/quarto.mk44
2 files changed, 49 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 88016be..97fdefa 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,12 @@
+DOCUMENTS = rapport
+
PAD_LIST = _NOTES.qmd:bp3data
# config hints used by helper script hedgedoc
export HEDGEDOC_SERVER = https://pad.degrowth.net/
export HEDGEDOC_CONFIG_DIR = $(CURDIR)/_hedgedoc
+# match danish appendix header
+DOCUMENT_APPENDIX_REGEX = Bilag\\b
+
include _make/*.mk
diff --git a/_make/quarto.mk b/_make/quarto.mk
new file mode 100644
index 0000000..12ca445
--- /dev/null
+++ b/_make/quarto.mk
@@ -0,0 +1,44 @@
+# 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 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-%: %/index.qmd
+ quarto render $<
+
+$(DOCUMENTS:%=doc-screening-of-%): doc-screening-of-%: %/index.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-%: %/index.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-%)