From 9020a9381ca281e521546af7d5780d7e2edf9dab Mon Sep 17 00:00:00 2001 From: Volpeon Date: Mon, 20 Jun 2022 16:58:31 +0200 Subject: WIP: Hashing all static assets --- Makefile copy | 215 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 Makefile copy (limited to 'Makefile copy') diff --git a/Makefile copy b/Makefile copy new file mode 100644 index 0000000..52d4dd8 --- /dev/null +++ b/Makefile copy @@ -0,0 +1,215 @@ +export DEPLOY_TARGET = vulpes@94.130.78.123:/srv/http/volpeon.ink/ + +-include Env.mk + +# +# FILE GROUPS +# + +PANDOC_FILTERS := $(patsubst %,--lua-filter %,$(wildcard filters/*.lua)) +GLOBAL_METADATA := $(patsubst %,--metadata-file %,$(wildcard metadata/*.yaml)) + +CONTENT_SRC := $(shell find content -type f -name "*.md") +FEED_SRC := $(shell grep -l "^feed: *true$$" $(CONTENT_SRC)) +CONTENT_TEMPLATES_SRC := $(shell find templates -type f -name "*.html") +FEED_TEMPLATES_SRC := $(shell find templates -type f -name "*.xml") +CSS_SRC := $(shell find assets/css -type f -name "*.scss") + +CONTENT_META := $(patsubst content/%.md,.cache/meta/%.json,$(CONTENT_SRC)) +CONTENT_FILES := $(patsubst content/%.md,out/%.html,$(CONTENT_SRC)) +FEED_FILES := $(patsubst content/%.md,out/%.xml,$(FEED_SRC)) +FONT_FILES := $(patsubst assets/fonts/%.ttf,out/%.woff2,$(wildcard assets/fonts/*.ttf)) +CSS_FILES := $(patsubst assets/css/%.scss,out/%.css,$(wildcard assets/css/style.scss)) +STATIC_FILES := $(patsubst content/%,out/%,$(shell find content -type f ! -name "*.md")) +STATIC_HASHED_FILES := $(filter out/%.css out/%.js out/%.svg out/%.woff2,$(STATIC_FILES)) + +# +# TARGETS +# + +all: content_meta content_files feed_files font_files css_files static_files icons + +content_meta: $(CONTENT_META) +content_files: $(CONTENT_FILES) +feed_files: $(FEED_FILES) +font_files: $(FONT_FILES) +css_files: $(CSS_FILES) +static_files: $(STATIC_FILES) + +# +# RULES +# + +.SECONDEXPANSION: + +namespace = $(patsubst %/index,%,$(patsubst %.json,%,$(patsubst $(2)%,%,$(1)))) + +subpages = $(patsubst content/%.md,.cache/meta/%.json, \ + $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -maxdepth 1 -type f -name "*.md" ! -name "index.md") \ + $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -mindepth 2 -maxdepth 2 -type f -name "index.md")) + +.cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) filters/*.lua scripts/subpages.lua scripts/subpages.jq scripts/metadata_tpl.json | .cache/meta + $(info [META] $< -> $@) + + mkdir -p $(@D) + $(eval PAGES_FILES = $(filter .cache/meta/%.json,$^)) + $(eval NAMESPACE = $(call namespace,$@,.cache/meta)) + $(if $(PAGES_FILES),jq -s --arg namespace "$(NAMESPACE)" -f scripts/subpages.jq $(PAGES_FILES) > "$@.pages",echo "{}" > "$@.pages") + pandoc \ + -f markdown-citations-implicit_figures \ + -t html5 \ + --wrap preserve \ + --no-highlight \ + --template scripts/metadata_tpl.json \ + --metadata namespace="$(NAMESPACE)" \ + --metadata file_out="$(patsubst .cache/meta/%.json,out/%.html,$@)" \ + --metadata-file "$@.pages" \ + $(PANDOC_FILTERS) \ + -o "$@.meta" "$<" + pandoc \ + -f markdown-citations-implicit_figures \ + -t html5 \ + --wrap preserve \ + --lua-filter scripts/metadata_filter.lua \ + --lua-filter scripts/subpages.lua \ + $(GLOBAL_METADATA) \ + --metadata-file "$@.meta" \ + --metadata file_out="$@" \ + $(PANDOC_FILTERS) \ + -o "$@.content" "$<" + jq '. + { content: $$content }' --rawfile content "$@.content" "$@.meta" > "$@" + rm "$@.pages" + rm "$@.meta" + rm "$@.content" + +.cache/hash.json: $(STATIC_HASHED_FILES) | .cache + echo "$^" + shell sha256sum "$^" | sed -r 's/([0-9a-f]+) +.*\/(.*)/"\2": "\1"/' + +out/%.html: content/%.md .cache/meta/%.json .cache/hash.json $(CONTENT_TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata_filter.lua out/style.css | out + $(info [MARK] $< -> $@) + + mkdir -p $(@D) + pandoc \ + -f markdown-citations-implicit_figures \ + -t html5 \ + --wrap preserve \ + --no-highlight \ + --template templates/base.html \ + --lua-filter scripts/metadata_filter.lua \ + $(GLOBAL_METADATA) \ + --metadata-file ".cache/hash.json" \ + --metadata-file "$(filter .cache/meta/%.json,$^)" \ + --metadata file_out="$@" \ + $(PANDOC_FILTERS) \ + -o "$@" "$<" + +out/%.xml: content/%.md .cache/meta/%.json $(FEED_TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata_filter.lua | out + $(info [FEED] $< -> $@) + + mkdir -p $(@D) + pandoc \ + -f markdown-citations-implicit_figures \ + -t html5 \ + --wrap preserve \ + --no-highlight \ + --template templates/feed.xml \ + --lua-filter scripts/metadata_filter.lua \ + $(GLOBAL_METADATA) \ + --metadata-file "$(filter .cache/meta/%.json,$^)" \ + --metadata file_out="$@" \ + $(PANDOC_FILTERS) \ + -o "$@" "$<" + +out/%/thumbnail.png: content/%/thumbnail.png | out + $(info [THMB] $< -> $@) + + convert -thumbnail 550x280^ -gravity center -extent 550x280 "$<" png:- | pngquant -o "$@" - + +out/%/thumbnail.jpg: content/%/thumbnail.jpg | out + $(info [THMB] $< -> $@) + + convert -thumbnail 550x280^ -gravity center -extent 550x280 "$<" ppm:- | cjpeg -quality 80 > "$@" + +out/%.woff2: assets/fonts/%.ttf assets/fonts/glyphs.txt | out + $(info [FONT] $< -> $@) + + pyftsubset "$<" \ + --text-file="assets/fonts/glyphs.txt" \ + --layout-features+=ss09,dlig \ + --flavor="woff2" \ + --output-file="$@" + +out/%.css: assets/css/%.scss $(CSS_SRC) | out + $(info [SCSS] $< -> $@) + + sass --load-path=node_modules "$<" | ./node_modules/.bin/postcss --use autoprefixer --no-map -o "$@" + +out/%: content/% | out + $(info [COPY] $< -> $@) + + mkdir -p $(@D) + cp "$<" "$@" + +icons: | out + $(info [ICON] out/icons.svg) + + node ./node_modules/iro-icons/scripts/create_sprite.js \ + asterisk \ + arrow-left \ + arrow-right \ + arrow-up-right \ + shuffle \ + envelope \ + hash \ + messages \ + parallelogram \ + globe \ + image \ + graph \ + git-branch \ + smile \ + link \ + x \ + chevron-left \ + chevron-right \ + "out/icons.svg" + +.cache/hash: | .cache + mkdir -p .cache/hash + +.cache/meta: | .cache + mkdir -p .cache/meta + +.cache: + mkdir -p .cache + +out: + mkdir -p out + +# +# UTILITIES +# + +watch: all + while true; do \ + inotifywait -qr -e modify -e create -e delete -e move assets content filters metadata scripts templates; \ + $(MAKE); \ + done + +serve: all + python -m http.server --bind 127.0.0.1 --directory out 8000 + +dev: watch serve + +compress: all + pigz -R -k -9 -- `find out -type f -iregex '.*\\.\\(css\\|js\\|json\\|html\\|xml\\|txt\\|svg\\|ico\\)'` + brotli -k -- `find out -type f -iregex '.*\\.\\(css\\|js\\|json\\|html\\|xml\\|txt\\|svg\\|ico\\|woff\\)'` + +deploy: compress + rsync --progress --stats -rvz --delete out/ "$(DEPLOY_TARGET)" + +clean: + rm -rf out + +.PHONY: all watch serve dev deploy clean -- cgit v1.2.3-70-g09d2