From a48d05d1d5fcff414359c8ba6cc8f38467aebdeb Mon Sep 17 00:00:00 2001 From: Volpeon Date: Mon, 10 May 2021 16:41:05 +0200 Subject: Refactoring to fully take advantage of Make --- Makefile | 178 ++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 125 insertions(+), 53 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index db7db81..a42f693 100644 --- a/Makefile +++ b/Makefile @@ -1,55 +1,127 @@ -all: build +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") +TEMPLATES_SRC := $(shell find templates -type f -name "*.html") +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)) +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")) + +# +# TARGETS +# + +all: content_meta content_files static_files font_files css_files + +content_meta: $(CONTENT_META) +content_files: $(CONTENT_FILES) +static_files: $(STATIC_FILES) +font_files: $(FONT_FILES) +css_files: $(CSS_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,$$@,)) scripts/subpages.jq | .cache/meta + $(info [META] $< -> $@) + + mkdir -p $(@D) + $(eval PAGES_FILES = $(filter .cache/meta/%.json,$^)) + $(eval PAGES = $(shell mktemp)) + $(eval NAMESPACE = $(call namespace,$@,.cache/meta)) + $(file >$(PAGES),$(if $(PAGES_FILES),$(shell jq -s --arg namespace "$(NAMESPACE)" -f scripts/subpages.jq $(PAGES_FILES)),)) + pandoc \ + -f markdown-citations \ + -t plain \ + --no-highlight \ + --template scripts/metadata_tpl.json \ + --metadata namespace="$(NAMESPACE)" \ + --metadata file_out="$(patsubst .cache/meta/%.json,out/%.html,$@)" \ + --metadata-file "$(PAGES)" \ + -o "$@" "$<" + rm "$(PAGES)" + +out/%.html: content/%.md .cache/meta/%.json $(TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata_filter.lua | out + $(info [MARK] $< -> $@) + + mkdir -p $(@D) + pandoc \ + -f markdown-citations \ + -t html5 \ + --no-highlight \ + --template templates/base.html \ + --lua-filter scripts/metadata_filter.lua \ + $(GLOBAL_METADATA) \ + --metadata-file "$(filter .cache/meta/%.json,$^)" \ + $(PANDOC_FILTERS) \ + -o "$@" "$<" + +out/%: content/% | out + $(info [COPY] $< -> $@) + + mkdir -p $(@D) + cp "$<" "$@" + +out/%.woff2: assets/fonts/%.ttf assets/fonts/glyphs.txt | out + $(info [FONT] $< -> $@) + + pyftsubset "$<" \ + --text-file="assets/fonts/glyphs.txt" \ + --layout-features+=ss02,ss09,dlig \ + --flavor="woff2" \ + --output-file="$@" + +out/%.css: assets/css/%.scss $(CSS_SRC) | out + $(info [SCSS] $< -> $@) + + sassc -t compressed "$<" | ./node_modules/.bin/postcss --use autoprefixer --no-map > "$@" + +.cache/meta: .cache + mkdir -p .cache/meta + +.cache/pages: .cache + mkdir -p .cache/pages + +.cache: + mkdir -p .cache + +out: + mkdir -p out + +# +# UTILITIES +# + +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\\)'` + +serve: all + python -m http.server --directory out 8000 + +#deploy: compress +# rsync --progress --stats -rvz --delete out "$(DEPLOY_TARGET)" clean: - @mkdir -p output - @rm -rf output/* - -build_fonts: clean - @scripts/build_fonts.sh - -build_sass: clean - @scripts/build_sass.sh - -build_content: clean - @scripts/build_content.sh - -build_only: build_fonts build_sass build_content - -compress_gz: build_only - @echo -e "\033[0;32m[COMPRESS]\033[0m Gzip" - @pigz -R -k -9 -- `find output -type f -iregex '.*\\.\\(css\\|js\\|json\\|html\\|xml\\|txt\\|svg\\|ico\\)'` - -compress_br: build_only - @echo -e "\033[0;32m[COMPRESS]\033[0m Brotli" - @brotli -k -- `find output -type f -iregex '.*\\.\\(css\\|js\\|json\\|html\\|xml\\|txt\\|svg\\|ico\\|woff\\)'` - -build: export LIVE=false -build: compress_gz compress_br - -watch_sass: build_only - @scripts/watch_sass.sh - -watch_content: build_only - @scripts/watch_content.sh - -watch_templates: build_only - @scripts/watch_templates.sh - -watch_metadata: build_only - @scripts/watch_metadata.sh - -watch_filters: build_only - @scripts/watch_filters.sh - -watch: export LIVE=true -watch: watch_sass watch_content watch_templates watch_metadata watch_filters - -serve_only: build_only - @python -m http.server --bind 127.0.0.1 --directory output - -serve: watch serve_only - -deploy: build - @scripts/deploy.sh - -.PHONY: all clean build watch serve deploy + rm -rf out -- cgit v1.2.3-70-g09d2