blob: 5e2fe8ab8c945da37be230b63ee712641d712ccc (
plain)
- # 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/>
- # * perl v5.10.1 or newer
- #
- # Suggestions:
- # * glow <https://github.com/charmbracelet/glow>
- # * bat <https://github.com/sharkdp/bat>, with executable named "batcat"
- # 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
- # pick as decent a Markdown pager as locally available
- _which = $(shell command -v $1 >/dev/null 2>&1 && echo $1 $2)
- CAT ?= $(strip $(or \
- $(call _which,glow,--pager),\
- $(call _which,batcat,--language markdown),\
- cat))
- PDF_DOCUMENTS ?= $(patsubst %.qmd,_site/%.pdf,$(DOCUMENTS))
- $(DOCUMENTS:%=doc-render-%): doc-render-%: _site/%.pdf
- _site/%.pdf: %.qmd
- quarto render $<
- $(DOCUMENTS:%=doc-screening-of-%): doc-screening-of-%: %.qmd
- QUARTO_LOG_LEVEL=quiet \
- quarto render $< --to markdown --output - | $(CAT)
- # 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-%)
|