blog/Makefile

133 lines
3.4 KiB
Makefile
Raw Normal View History

2024-11-29 00:51:25 +01:00
HOST ?= niss.website
2021-07-24 03:35:02 +02:00
REMOTE_USER ?= www-data
REMOTE_DIR ?= blog
TMPDIR ?= _tmp
2024-11-29 00:51:25 +01:00
BUILDDIR ?= /srv/www/blog
2021-07-24 03:35:02 +02:00
POSTSDIR ?= posts
2023-12-28 01:00:25 +01:00
IMAGESDIR ?= images
2021-07-24 03:35:02 +02:00
TEMPLATEDIR ?= templates
2024-11-29 00:51:25 +01:00
STATICS := \
$(subst $(POSTSDIR)/,, $(shell find $(POSTSDIR) -type f -not -iname '*.md')) \
$(shell find $(IMAGESDIR) -type f)
2022-03-16 04:54:57 +01:00
2021-07-24 03:35:02 +02:00
POSTS != find $(POSTSDIR) -name '*.md'
OUTPUTPOSTS = \
$(patsubst $(POSTSDIR)/%.md,$(BUILDDIR)/%.html,$(POSTS)) \
2023-12-28 01:00:25 +01:00
$(addprefix $(BUILDDIR)/,$(STATICS)) \
2024-09-15 17:49:23 +02:00
$(BUILDDIR)/index.html $(BUILDDIR)/rss.xml
2021-07-24 03:35:02 +02:00
STYLE != find style -type f
OUTPUTSTYLE = $(patsubst %,$(BUILDDIR)/%,$(STYLE))
OUTPUT = $(OUTPUTPOSTS) $(OUTPUTSTYLE)
ALL_TAGS = $(TMPDIR)/all-tags
POST_LISTS = $(TMPDIR)/post-lists
COMBO_FILTER = $(TMPDIR)/combo-filter
2021-07-24 03:35:02 +02:00
EXECS = \
2023-12-28 01:00:25 +01:00
$(LAANTAS_SCRIPT) \
$(ALL_TAGS) $(POST_LISTS) $(COMBO_FILTER)
2021-07-24 03:35:02 +02:00
2023-12-28 01:00:25 +01:00
CABAL_FLAGS ?= -O
2021-07-24 03:35:02 +02:00
2022-03-15 04:40:25 +01:00
SYNTAXDIR := syntax
2022-03-16 18:39:53 +01:00
SYNTAXFILES != find $(SYNTAXDIR) -name *.xml
SYNTAXFLAGS = $(patsubst %,--syntax-definition=%,$(SYNTAXFILES))
2022-03-15 04:40:25 +01:00
2021-07-24 03:35:02 +02:00
.PHONY: all
all: build
.PHONY: build
build: $(EXECS) $(OUTPUT)
2023-12-28 01:00:25 +01:00
POSTDEPS = \
$(TEMPLATEDIR)/* \
$(SYNTAXFILES) acm.csl quox.bib
2021-07-24 03:35:02 +02:00
$(TMPDIR)/all-tags.md $(TMPDIR)/tags.mk &: $(POSTS) $(ALL_TAGS)
@echo "[all-tags]"
$(ALL_TAGS) $(POSTSDIR) $(TMPDIR)/all-tags.md $(TMPDIR)/tags.mk
build: $(BUILDDIR)/all-tags.html
include $(TMPDIR)/tags.mk
2024-09-15 17:49:23 +02:00
$(BUILDDIR)/%.html: $(POSTSDIR)/%.md $(POSTDEPS) ; $(call pandoc,post.html)
$(BUILDDIR)/%.html: $(TMPDIR)/%.md $(POSTDEPS) ; $(call pandoc-simple,meta.html)
2024-09-15 17:49:23 +02:00
$(BUILDDIR)/rss.xml: $(TMPDIR)/index.md $(POSTDEPS)
$(call pandoc,rss.xml,--metadata-file rss.yaml --write html)
2021-07-24 03:35:02 +02:00
2023-12-28 01:00:25 +01:00
.PHONY: langfilter laantas-script
langfilter laantas-script: %: ; cabal build $@
2024-09-15 17:49:23 +02:00
# $(1): template file
# $(2): extra flags
2021-07-24 03:35:02 +02:00
define pandoc
2024-09-15 17:49:23 +02:00
@echo "[pandoc] $(subst $(TMPDIR)/,,$(subst $(BUILDDIR)/,,$@))"
2021-07-24 03:35:02 +02:00
mkdir -p $(dir $@)
mkdir -p $(basename $@)
LANG_COLOR="currentcolor" \
2024-09-15 17:49:23 +02:00
pandoc -s --toc --toc-depth=2 --template $(TEMPLATEDIR)/$(1) -o $@ $< \
-f markdown+emoji $(2) \
2024-11-29 00:51:25 +01:00
-M filename=$(subst $(BUILDDIR)/,,$@) --metadata-file=rss.yaml \
$(SYNTAXFLAGS) --filter $(COMBO_FILTER) \
2024-09-15 17:48:16 +02:00
--mathml --citeproc --csl=apa-eu.csl
2021-07-24 03:35:02 +02:00
endef
# $(1): template file
define pandoc-simple
@echo "[pandoc] $(subst $(TMPDIR)/,,$(subst $(BUILDDIR)/,,$@))"
mkdir -p $(dir $@)
mkdir -p $(basename $@)
pandoc -s --template $(TEMPLATEDIR)/$(1) -o $@ $< \
-M filename=$(subst $(BUILDDIR)/,,$@) --metadata-file=rss.yaml
endef
2021-07-24 03:35:02 +02:00
2023-12-28 01:00:25 +01:00
$(BUILDDIR)/%: $(POSTSDIR)/% ; $(call copy)
$(BUILDDIR)/%: $(TMPDIR)/% ; $(call copy)
$(BUILDDIR)/%: % ; $(call copy)
2021-07-24 03:35:02 +02:00
define copy
@echo "[copy] $<"
mkdir -p $(dir $@)
cp $< $@
endef
BLOG_META_DEPS != find blog-meta -type f
$(ALL_TAGS): $(BLOG_META_DEPS) ; $(call cabal-exe,blog-meta:)
$(POST_LISTS): $(BLOG_META_DEPS) ; $(call cabal-exe,blog-meta:)
$(COMBO_FILTER): $(BLOG_META_DEPS) ; $(call cabal-exe,blog-meta:)
2021-07-24 03:35:02 +02:00
define cabal-exe
@echo "[build] $(notdir $@)"
cabal build $(1)$(notdir $@) $(CABAL_FLAGS)
mkdir -p $(dir $@)
find dist-newstyle -name $(notdir $@) -type f -exec cp {} $(TMPDIR) \;
endef
upload: build
@echo "[upload]"
@rsync --recursive --partial --progress --copy-links \
2024-12-03 17:53:57 +01:00
--compress --human-readable --hard-links \
2021-07-24 03:35:02 +02:00
--delete --delete-after \
2024-11-29 00:51:25 +01:00
--rsh='ssh -l $(REMOTE_USER)' \
2021-07-24 03:35:02 +02:00
$(BUILDDIR)/ $(HOST):$(REMOTE_DIR)/
.PHONY: clean distclean
clean:
@echo "[clean]"
rm -rf $(BUILDDIR)
rm -rf $(TMPDIR)
distclean: clean
@echo "[distclean]"
cabal clean
.SILENT: