diff options
author | Volpeon <git@volpeon.ink> | 2021-05-10 16:41:05 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2021-05-10 16:41:05 +0200 |
commit | a48d05d1d5fcff414359c8ba6cc8f38467aebdeb (patch) | |
tree | 3542bf116c910a1bb42b40d8531f60c2c2498b08 /Makefile | |
parent | Update (diff) | |
download | volpeon.ink-a48d05d1d5fcff414359c8ba6cc8f38467aebdeb.tar.gz volpeon.ink-a48d05d1d5fcff414359c8ba6cc8f38467aebdeb.tar.bz2 volpeon.ink-a48d05d1d5fcff414359c8ba6cc8f38467aebdeb.zip |
Refactoring to fully take advantage of Make
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 178 |
1 files changed, 125 insertions, 53 deletions
@@ -1,55 +1,127 @@ | |||
1 | all: build | 1 | export DEPLOY_TARGET = "vulpes@94.130.78.123:/srv/http/volpeon.ink/" |
2 | |||
3 | -include Env.mk | ||
4 | |||
5 | # | ||
6 | # FILE GROUPS | ||
7 | # | ||
8 | |||
9 | PANDOC_FILTERS := $(patsubst %,--lua-filter %,$(wildcard filters/*.lua)) | ||
10 | GLOBAL_METADATA := $(patsubst %,--metadata-file %,$(wildcard metadata/*.yaml)) | ||
11 | |||
12 | CONTENT_SRC := $(shell find content -type f -name "*.md") | ||
13 | TEMPLATES_SRC := $(shell find templates -type f -name "*.html") | ||
14 | CSS_SRC := $(shell find assets/css -type f -name "*.scss") | ||
15 | |||
16 | CONTENT_META := $(patsubst content/%.md,.cache/meta/%.json,$(CONTENT_SRC)) | ||
17 | CONTENT_FILES := $(patsubst content/%.md,out/%.html,$(CONTENT_SRC)) | ||
18 | FONT_FILES := $(patsubst assets/fonts/%.ttf,out/%.woff2,$(wildcard assets/fonts/*.ttf)) | ||
19 | CSS_FILES := $(patsubst assets/css/%.scss,out/%.css,$(wildcard assets/css/style.scss)) | ||
20 | STATIC_FILES := $(patsubst content/%,out/%,$(shell find content -type f ! -name "*.md")) | ||
21 | |||
22 | # | ||
23 | # TARGETS | ||
24 | # | ||
25 | |||
26 | all: content_meta content_files static_files font_files css_files | ||
27 | |||
28 | content_meta: $(CONTENT_META) | ||
29 | content_files: $(CONTENT_FILES) | ||
30 | static_files: $(STATIC_FILES) | ||
31 | font_files: $(FONT_FILES) | ||
32 | css_files: $(CSS_FILES) | ||
33 | |||
34 | # | ||
35 | # RULES | ||
36 | # | ||
37 | |||
38 | .SECONDEXPANSION: | ||
39 | |||
40 | namespace = $(patsubst %/index,%,$(patsubst %.json,%,$(patsubst $(2)%,%,$(1)))) | ||
41 | |||
42 | subpages = $(patsubst content/%.md,.cache/meta/%.json, \ | ||
43 | $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -maxdepth 1 -type f -name "*.md" ! -name "index.md") \ | ||
44 | $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -mindepth 2 -maxdepth 2 -type f -name "index.md")) | ||
45 | |||
46 | .cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) scripts/subpages.jq | .cache/meta | ||
47 | $(info [META] $< -> $@) | ||
48 | |||
49 | mkdir -p $(@D) | ||
50 | $(eval PAGES_FILES = $(filter .cache/meta/%.json,$^)) | ||
51 | $(eval PAGES = $(shell mktemp)) | ||
52 | $(eval NAMESPACE = $(call namespace,$@,.cache/meta)) | ||
53 | $(file >$(PAGES),$(if $(PAGES_FILES),$(shell jq -s --arg namespace "$(NAMESPACE)" -f scripts/subpages.jq $(PAGES_FILES)),)) | ||
54 | pandoc \ | ||
55 | -f markdown-citations \ | ||
56 | -t plain \ | ||
57 | --no-highlight \ | ||
58 | --template scripts/metadata_tpl.json \ | ||
59 | --metadata namespace="$(NAMESPACE)" \ | ||
60 | --metadata file_out="$(patsubst .cache/meta/%.json,out/%.html,$@)" \ | ||
61 | --metadata-file "$(PAGES)" \ | ||
62 | -o "$@" "$<" | ||
63 | rm "$(PAGES)" | ||
64 | |||
65 | out/%.html: content/%.md .cache/meta/%.json $(TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata_filter.lua | out | ||
66 | $(info [MARK] $< -> $@) | ||
67 | |||
68 | mkdir -p $(@D) | ||
69 | pandoc \ | ||
70 | -f markdown-citations \ | ||
71 | -t html5 \ | ||
72 | --no-highlight \ | ||
73 | --template templates/base.html \ | ||
74 | --lua-filter scripts/metadata_filter.lua \ | ||
75 | $(GLOBAL_METADATA) \ | ||
76 | --metadata-file "$(filter .cache/meta/%.json,$^)" \ | ||
77 | $(PANDOC_FILTERS) \ | ||
78 | -o "$@" "$<" | ||
79 | |||
80 | out/%: content/% | out | ||
81 | $(info [COPY] $< -> $@) | ||
82 | |||
83 | mkdir -p $(@D) | ||
84 | cp "$<" "$@" | ||
85 | |||
86 | out/%.woff2: assets/fonts/%.ttf assets/fonts/glyphs.txt | out | ||
87 | $(info [FONT] $< -> $@) | ||
88 | |||
89 | pyftsubset "$<" \ | ||
90 | --text-file="assets/fonts/glyphs.txt" \ | ||
91 | --layout-features+=ss02,ss09,dlig \ | ||
92 | --flavor="woff2" \ | ||
93 | --output-file="$@" | ||
94 | |||
95 | out/%.css: assets/css/%.scss $(CSS_SRC) | out | ||
96 | $(info [SCSS] $< -> $@) | ||
97 | |||
98 | sassc -t compressed "$<" | ./node_modules/.bin/postcss --use autoprefixer --no-map > "$@" | ||
99 | |||
100 | .cache/meta: .cache | ||
101 | mkdir -p .cache/meta | ||
102 | |||
103 | .cache/pages: .cache | ||
104 | mkdir -p .cache/pages | ||
105 | |||
106 | .cache: | ||
107 | mkdir -p .cache | ||
108 | |||
109 | out: | ||
110 | mkdir -p out | ||
111 | |||
112 | # | ||
113 | # UTILITIES | ||
114 | # | ||
115 | |||
116 | compress: all | ||
117 | pigz -R -k -9 -- `find out -type f -iregex '.*\\.\\(css\\|js\\|json\\|html\\|xml\\|txt\\|svg\\|ico\\)'` | ||
118 | brotli -k -- `find out -type f -iregex '.*\\.\\(css\\|js\\|json\\|html\\|xml\\|txt\\|svg\\|ico\\|woff\\)'` | ||
119 | |||
120 | serve: all | ||
121 | python -m http.server --directory out 8000 | ||
122 | |||
123 | #deploy: compress | ||
124 | # rsync --progress --stats -rvz --delete out "$(DEPLOY_TARGET)" | ||
2 | 125 | ||
3 | clean: | 126 | clean: |
4 | @mkdir -p output | 127 | rm -rf out |
5 | @rm -rf output/* | ||
6 | |||
7 | build_fonts: clean | ||
8 | @scripts/build_fonts.sh | ||
9 | |||
10 | build_sass: clean | ||
11 | @scripts/build_sass.sh | ||
12 | |||
13 | build_content: clean | ||
14 | @scripts/build_content.sh | ||
15 | |||
16 | build_only: build_fonts build_sass build_content | ||
17 | |||
18 | compress_gz: build_only | ||
19 | @echo -e "\033[0;32m[COMPRESS]\033[0m Gzip" | ||
20 | @pigz -R -k -9 -- `find output -type f -iregex '.*\\.\\(css\\|js\\|json\\|html\\|xml\\|txt\\|svg\\|ico\\)'` | ||
21 | |||
22 | compress_br: build_only | ||
23 | @echo -e "\033[0;32m[COMPRESS]\033[0m Brotli" | ||
24 | @brotli -k -- `find output -type f -iregex '.*\\.\\(css\\|js\\|json\\|html\\|xml\\|txt\\|svg\\|ico\\|woff\\)'` | ||
25 | |||
26 | build: export LIVE=false | ||
27 | build: compress_gz compress_br | ||
28 | |||
29 | watch_sass: build_only | ||
30 | @scripts/watch_sass.sh | ||
31 | |||
32 | watch_content: build_only | ||
33 | @scripts/watch_content.sh | ||
34 | |||
35 | watch_templates: build_only | ||
36 | @scripts/watch_templates.sh | ||
37 | |||
38 | watch_metadata: build_only | ||
39 | @scripts/watch_metadata.sh | ||
40 | |||
41 | watch_filters: build_only | ||
42 | @scripts/watch_filters.sh | ||
43 | |||
44 | watch: export LIVE=true | ||
45 | watch: watch_sass watch_content watch_templates watch_metadata watch_filters | ||
46 | |||
47 | serve_only: build_only | ||
48 | @python -m http.server --bind 127.0.0.1 --directory output | ||
49 | |||
50 | serve: watch serve_only | ||
51 | |||
52 | deploy: build | ||
53 | @scripts/deploy.sh | ||
54 | |||
55 | .PHONY: all clean build watch serve deploy | ||