diff options
| author | Joe Carstairs <me@joeac.net> | 2026-06-30 13:02:19 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-06-30 13:02:19 +0100 |
| commit | 0472a6fa83a0baa817ded401df41893af92831e8 (patch) | |
| tree | 976f05c40e0f5c5020848eb72b2996a884aa3263 | |
| parent | afcd5ded9d97217974a21648204052bc7072d475 (diff) | |
caches wordcounts in .wc files
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 27 |
2 files changed, 21 insertions, 7 deletions
@@ -3,3 +3,4 @@ dissertation.md dissertation.latex dissertation-no-references.latex +*.wc @@ -5,20 +5,25 @@ WORDCOUNT_FILTER := filters/wordcount.lua DISSERTATION_FRONTMATTER := frontmatter.yml DISSERTATION_MARKDOWN := dissertation.md CHAPTER_MARKDOWN_FILES := $(wildcard chapter*.md) +CHAPTER_MARKDOWN_FILE_PATTERN := chapter%.md CHAPTER_INDICES := $(CHAPTER_MARKDOWN_FILES:chapter%.md=%) +CHAPTER_WORDCOUNT_FILE_PATTERN := .chapter%.wc +CHAPTER_WORDCOUNT_FILES := $(CHAPTER_INDICES:%=$(CHAPTER_WORDCOUNT_FILE_PATTERN)) LOG_MARKDOWN := log.md SCRAPBOOK_MARKDOWN := scrapbook.md DISSERTATION_LATEX := dissertation.latex DISSERTATION_LATEX_NO_REFERENCES := dissertation-no-references.latex +DISSERTATION_WORDCOUNT_FILE := .dissertation.wc DISSERTATION_PDF := dissertation.pdf DISSERTATION_PDF_NO_REFERENCES := dissertation-no-references.pdf LOG_PDF := log.pdf SCRAPBOOK_PDF := scrapbook.pdf -chapter_markdown = chapter$(chapter_index).md -chapter_title = $(shell head -n 1 $(chapter_markdown) | cut -c4-) +chapter_markdown_file = chapter$(chapter_index).md +chapter_wordcount_file = .chapter$(chapter_index).wc +chapter_title = $(shell head -n 1 $(chapter_markdown_file) | cut -c4-) -all: log scrapbook dissertation +all: log scrapbook dissertation wordcount watch: ifdef TARGET @@ -94,13 +99,21 @@ $(DISSERTATION_MARKDOWN): $(DISSERTATION_FRONTMATTER) $(CHAPTER_MARKDOWN_FILES) echo "" >> $(DISSERTATION_MARKDOWN) .SILENT: wordcount -wordcount: $(DISSERTATION_PDF_NO_REFERENCES) +.PHONY: wordcount +wordcount: $(CHAPTER_WORDCOUNT_FILES) $(DISSERTATION_WORDCOUNT_FILE) $(foreach chapter_index,$(CHAPTER_INDICES), \ - echo "$(chapter_title): $$(pandoc --lua-filter $(WORDCOUNT_FILTER) $(chapter_markdown))"; \ + echo "$(chapter_title): $(shell cat $(chapter_wordcount_file))"; \ ) echo "Footnotes: ???" echo "References: ???" - echo "Total: $$(pdfgrep -o '\w+' $(DISSERTATION_PDF_NO_REFERENCES) | wc -w) ($$(pandoc --lua-filter $(WORDCOUNT_FILTER) $(DISSERTATION_MARKDOWN)) + footnotes)" + echo "Total: $(shell cat $(DISSERTATION_WORDCOUNT_FILE))" + +$(CHAPTER_WORDCOUNT_FILE_PATTERN): $(CHAPTER_MARKDOWN_FILE_PATTERN) $(WORDCOUNT_FILTER) + pandoc --lua-filter $(WORDCOUNT_FILTER) $< > $@ + +$(DISSERTATION_WORDCOUNT_FILE): $(DISSERTATION_PDF_NO_REFERENCES) $(WORDCOUNT_FILTER) $(DISSERTATION_MARKDOWN) + echo "$(shell pdfgrep -o '\w+' $(DISSERTATION_PDF_NO_REFERENCES) | wc -w) ($(shell pandoc --lua-filter $(WORDCOUNT_FILTER) $(DISSERTATION_MARKDOWN)) + footnotes)" \ + > $(DISSERTATION_WORDCOUNT_FILE) $(DISSERTATION_PDF_NO_REFERENCES): $(DISSERTATION_LATEX_NO_REFERENCES) pandoc \ @@ -118,4 +131,4 @@ $(DISSERTATION_LATEX_NO_REFERENCES): $(DISSERTATION_LATEX) tail -n +$$(( $(bib_end_line_index) + 1 )) $(DISSERTATION_LATEX) >> $(DISSERTATION_LATEX_NO_REFERENCES) clean: - rm -f $(LOG_PDF) $(SCRAPBOOK_PDF) $(DISSERTATION_MARKDOWN) $(DISSERTATION_LATEX) $(DISSERTATION_LATEX_NO_REFERENCES) $(DISSERTATION_PDF) $(DISSERTATION_PDF_NO_REFERENCES) + rm -f $(LOG_PDF) $(SCRAPBOOK_PDF) $(DISSERTATION_MARKDOWN) $(DISSERTATION_LATEX) $(DISSERTATION_LATEX_NO_REFERENCES) $(DISSERTATION_PDF) $(DISSERTATION_PDF_NO_REFERENCES) $(CHAPTER_WORDCOUNT_FILES) $(DISSERTATION_WORDCOUNT_FILE) |
