-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
82 lines (65 loc) · 3.12 KB
/
Copy pathMakefile
File metadata and controls
82 lines (65 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
markdown_files := $(shell find src -name '*.md')
compiled_markdown_files := $(patsubst src/%,compiled_markdown/%,$(markdown_files))
compiled_handlebars_files := $(patsubst %.md,%.html,$(patsubst src/%,compiled_handlebars/%,$(markdown_files)))
distributable_files := $(patsubst compiled_handlebars/%,dist/%,$(compiled_handlebar_files))
post_jsons := $(wildcard compiled_handlebars/posts/*.json)
all: clean_all $(compiled_markdown_files) fill_posts_json $(compiled_handlebars_files) compile_index move_styles prepare_dist clean move_cname move_generative move_the_sandmachine move_timetraveller
clean_all:
rm -r compiled_markdown || true
rm -r data || true
rm -r compiled_handlebars || true
rm -r dist || true
clean:
rm -r compiled_markdown || true
rm -r data || true
rm -r compiled_handlebars || true
compiled_markdown/%: src/%
mkdir -p $(dir $@)
# Use showdown to turn markdown into html, the output-file is the input-file but with html instead of md
npx showdown makehtml --input $< --output $(patsubst %.md,%.html,$@) -c metadata
sed -n "/^---/,/^---/ { /^---/d ; /^---/d ; /^$$/d ; p;}" $< > $(patsubst %.md,%.json,$@)
fill_posts_json:
mkdir -p data/
touch data/posts.json
# For every <post>.json file we get the title and use the filename as slug
# It is saved into posts.protojson because we don't want to be bothered with comma's
cd compiled_markdown/posts; \
for f in *.json; \
do echo "{ \"slug\": \"/posts/$$(echo $${f%.*})\", \"title\": $$(cat $$f | jq .title), \"description\": $$(cat $$f | jq .description), \"createdAt\": $$(cat $$f | jq .createdAt) }" >> ../posts.protojson; \
done; \
cd ../..;
# jq takes that protojson and formats it properly
echo "{ \"posts\": $$(cat compiled_markdown/posts.protojson | jq -s '. |= sort_by(.createdAt) | reverse') }" > data/posts.json
compiled_handlebars/%: compiled_markdown/%
mkdir -p $(dir $@)
# Replace instance of [[post]] in the posts-template with the contents of the post.html
sed -e "/\[\[post\]\]/{r $<" -e "d" -e "}" 'src/layouts/posts.html' > $@
# Render the handlebars, give it the metadata
# TODO: Expose partials and helpers
npx hbs --data $(patsubst %.html,%.json,$<) --data 'src/data/*.json' --data 'data/posts.json' $@ --output $(dir $@)
mkdir $(patsubst %.html,%,$@)
mv $@ $(patsubst %.html,%/index.html,$@)
compile_index:
# Render the handlebars of the index, give it the metadata
# TODO: Expose partials and helpers
npx hbs --data 'src/data/*.json' --data 'data/posts.json' src/index.html --output compiled_handlebars/
prepare_dist:
# A clean procedure to move the built files to the dist folder.
mkdir -p dist/posts
cp -r compiled_handlebars/posts/* dist/posts/
cp compiled_handlebars/index.html dist/index.html
cp data/posts.json dist/index.json
install:
npm install
move_styles:
mkdir -p dist/assets
cp -r src/assets dist/
move_cname:
cp CNAME dist/CNAME
move_generative:
cp -r ./genuary_2022 dist/
move_the_sandmachine:
cp -r ./the-sandmachine dist/
move_timetraveller:
mkdir -p dist/timetraveller
cp ./timetraveller/index.html ./timetraveller/main.js ./timetraveller/github.js ./timetraveller/render.js ./timetraveller/style.css dist/timetraveller/