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 | 146 |
1 files changed, 109 insertions, 37 deletions
| @@ -1,55 +1,127 @@ | |||
| 1 | all: build | 1 | export DEPLOY_TARGET = "vulpes@94.130.78.123:/srv/http/volpeon.ink/" |
| 2 | 2 | ||
| 3 | clean: | 3 | -include Env.mk |
| 4 | @mkdir -p output | 4 | |
| 5 | @rm -rf output/* | 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 | # | ||
| 6 | 25 | ||
| 7 | build_fonts: clean | 26 | all: content_meta content_files static_files font_files css_files |
| 8 | @scripts/build_fonts.sh | ||
| 9 | 27 | ||
| 10 | build_sass: clean | 28 | content_meta: $(CONTENT_META) |
| 11 | @scripts/build_sass.sh | 29 | content_files: $(CONTENT_FILES) |
| 30 | static_files: $(STATIC_FILES) | ||
| 31 | font_files: $(FONT_FILES) | ||
| 32 | css_files: $(CSS_FILES) | ||
| 12 | 33 | ||
| 13 | build_content: clean | 34 | # |
| 14 | @scripts/build_content.sh | 35 | # RULES |
| 36 | # | ||
| 15 | 37 | ||
| 16 | build_only: build_fonts build_sass build_content | 38 | .SECONDEXPANSION: |
| 17 | 39 | ||
| 18 | compress_gz: build_only | 40 | namespace = $(patsubst %/index,%,$(patsubst %.json,%,$(patsubst $(2)%,%,$(1)))) |
| 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 | 41 | ||
| 22 | compress_br: build_only | 42 | subpages = $(patsubst content/%.md,.cache/meta/%.json, \ |
| 23 | @echo -e "\033[0;32m[COMPRESS]\033[0m Brotli" | 43 | $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -maxdepth 1 -type f -name "*.md" ! -name "index.md") \ |
| 24 | @brotli -k -- `find output -type f -iregex '.*\\.\\(css\\|js\\|json\\|html\\|xml\\|txt\\|svg\\|ico\\|woff\\)'` | 44 | $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -mindepth 2 -maxdepth 2 -type f -name "index.md")) |
| 25 | 45 | ||
| 26 | build: export LIVE=false | 46 | .cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) scripts/subpages.jq | .cache/meta |
| 27 | build: compress_gz compress_br | 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)" | ||
| 28 | 64 | ||
| 29 | watch_sass: build_only | 65 | out/%.html: content/%.md .cache/meta/%.json $(TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata_filter.lua | out |
| 30 | @scripts/watch_sass.sh | 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 "$@" "$<" | ||
| 31 | 79 | ||
| 32 | watch_content: build_only | 80 | out/%: content/% | out |
| 33 | @scripts/watch_content.sh | 81 | $(info [COPY] $< -> $@) |
| 34 | 82 | ||
| 35 | watch_templates: build_only | 83 | mkdir -p $(@D) |
| 36 | @scripts/watch_templates.sh | 84 | cp "$<" "$@" |
| 37 | 85 | ||
| 38 | watch_metadata: build_only | 86 | out/%.woff2: assets/fonts/%.ttf assets/fonts/glyphs.txt | out |
| 39 | @scripts/watch_metadata.sh | 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="$@" | ||
| 40 | 94 | ||
| 41 | watch_filters: build_only | 95 | out/%.css: assets/css/%.scss $(CSS_SRC) | out |
| 42 | @scripts/watch_filters.sh | 96 | $(info [SCSS] $< -> $@) |
| 43 | 97 | ||
| 44 | watch: export LIVE=true | 98 | sassc -t compressed "$<" | ./node_modules/.bin/postcss --use autoprefixer --no-map > "$@" |
| 45 | watch: watch_sass watch_content watch_templates watch_metadata watch_filters | ||
| 46 | 99 | ||
| 47 | serve_only: build_only | 100 | .cache/meta: .cache |
| 48 | @python -m http.server --bind 127.0.0.1 --directory output | 101 | mkdir -p .cache/meta |
| 49 | 102 | ||
| 50 | serve: watch serve_only | 103 | .cache/pages: .cache |
| 104 | mkdir -p .cache/pages | ||
| 51 | 105 | ||
| 52 | deploy: build | 106 | .cache: |
| 53 | @scripts/deploy.sh | 107 | mkdir -p .cache |
| 54 | 108 | ||
| 55 | .PHONY: all clean build watch serve deploy | 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)" | ||
| 125 | |||
| 126 | clean: | ||
| 127 | rm -rf out | ||
