aboutsummaryrefslogtreecommitdiff
path: root/_make/quarto.mk
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-11-10 15:04:35 +0100
committerJonas Smedegaard <dr@jones.dk>2025-11-10 15:04:35 +0100
commit3631d051e7fd2c42b5b57dc0320224c524fd16ff (patch)
treec7d8cd6b5e8e2d03d47482334442ff97847bc9d4 /_make/quarto.mk
parentb98853afdee75a00ca53c593b3bcef2f99fa3ab5 (diff)
add makefile
Diffstat (limited to '_make/quarto.mk')
-rw-r--r--_make/quarto.mk56
1 files changed, 56 insertions, 0 deletions
diff --git a/_make/quarto.mk b/_make/quarto.mk
new file mode 100644
index 0000000..63ad617
--- /dev/null
+++ b/_make/quarto.mk
@@ -0,0 +1,56 @@
+# 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 expressions 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
+DOCUMENT_BIBLIOGRAPHY_REGEX ?= Bibliography\\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)"
+
+# count all characters except horisontal rulers,
+# until bibliography,
+# divide by 2400 and floor the result
+$(DOCUMENTS:%=doc-pagecount-of-%): doc-pagecount-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_BIBLIOGRAPHY_REGEX)" \
+ | perl -nE 'say int($$_ / 2400)'
+
+.PHONY: $(DOCUMENTS:%=doc-render-%) $(DOCUMENTS:%=doc-screening-of-%) \
+ $(DOCUMENTS:%=doc-charcount-of-%) $(DOCUMENTS:%=doc-pagecount-of-%)