summaryrefslogtreecommitdiff
path: root/Makefile
blob: 575cb6e12773608de51e0c3be8a1cfd59870801b (plain)
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
83
TITLE=Eugene's Space
RSYNC_DESTINATION=eug-vs.xyz:/var/www/website

MARKDOWN=gfm+emoji
STYLESHEET=/style.css
HEAD=head.html
HEADER=header.html
RSS_FEED=blog/index.xml
OPENRING_FOOTER=footer.html
PANDOC_ARGS= --from=$(MARKDOWN) --to=html
PANDOC_HTML_ARGS=-s $(PANDOC_ARGS) -c $(STYLESHEET) -B $(HEADER) -H $(HEAD) -M lang="en" --shift-heading-level-by=1 --highlight-style=gruvbox.theme

LINK_SEDSTRING=s/.md)/.html)/g;
EMOJI_SEDSTRING=$(shell ./compile_emoji_sedstring.sh)
LOCALIZE_SEDSTRING=s|\"/|\"$(PWD)/|;
UNLOCALIZE_SEDSTRING=s|$(PWD)||;

OPENRING_ARGS=$(shell ./compile_openring_args.sh)


SOURCES=$(wildcard *.md blog/*.md articles/*.md)
HTML=$(patsubst %.md, %.html, $(SOURCES))
XML=$(patsubst %.md, %.xml, $(filter-out blog/preview.md, $(filter-out blog/index.md, $(wildcard blog/*.md))))


all: $(HTML) $(RSS_FEED)

%.html: %.md $(OPENRING_FOOTER)
	@echo $@
	@DESCRIPTION=$$(sed '2,/^$$/!d' $< | tr '\n' ' '); \
		PAGETITLE=$$(sed '/^#/q' $< | sed 's/:[a-z]*://; s/#* //'); \
		sed "$(LINK_SEDSTRING) $(EMOJI_SEDSTRING)" $< \
		| pandoc $(PANDOC_HTML_ARGS) -M pagetitle="$$PAGETITLE | $(TITLE)" -A $(OPENRING_FOOTER) -M description="$$DESCRIPTION" > $@

%.xml: %.md
	@echo $@
	@echo '<item>' > $@
	@echo "  <link>https://eug-vs.xyz/$*.html</link>" >> $@
	@echo "  <pubDate>$*</pubDate>" >> $@
	@echo "  <title>$$(sed '/^#/q' $< | sed 's/:[a-z]*://; s/#* //')</title>" >> $@
	@echo "  <description><![CDATA[" >> $@
	@sed "$(LINK_SEDSTRING) $(EMOJI_SEDSTRING)" $< | pandoc $(PANDOC_ARGS) $< >> $@
	@echo "  ]]></description>" >> $@
	@echo '</item>' >> $@

$(RSS_FEED): $(XML)
	@echo $@
	@echo '<rss version="2.0"><channel>' > $@
	@echo "<title>Eugene's Space</title><link>https://eug-vs.xyz</link><description>Eugene's blog</description>" >> $@
	@cat $$(echo $^ | tr " " "\n" | sort -r | tr "\n" " ") >> $@
	@echo '</channel></rss>' >> $@

index.html: index.md blog/preview.md
	@echo $@
	@DESCRIPTION=$$(sed '2,/^$$/!d' $< | tr '\n' ' '); \
		sed "/Recent blog posts/r blog/preview.md" $< \
		| sed "$(LINK_SEDSTRING) $(EMOJI_SEDSTRING)" \
		| pandoc $(PANDOC_HTML_ARGS) -M pagetitle="$(TITLE)" -M description="$$DESCRIPTION"> $@

$(OPENRING_FOOTER): openring-template.html
	@echo $@
	@openring $(OPENRING_ARGS) < $< > $@

blog/preview.md: blog/index.md
	@echo $@
	@sed -n "s/^-/ -/; s|(|(blog/| ; /^ -/p" $< | head -n 4 > $@

open: $(HTML)
	xdg-open index.html

deploy: all
	$(MAKE) unlocalize
	rsync -rtvzP --include="$(RSS_FEED)" --exclude=".git" --exclude="*.md" --exclude="*.xml" . $(RSYNC_DESTINATION)

localize: $(HTML)
	@for file in $^; do sed -i "$(UNLOCALIZE_SEDSTRING) $(LOCALIZE_SEDSTRING)" $$file; done

unlocalize: $(HTML)
	@for file in $^; do sed -i "$(UNLOCALIZE_SEDSTRING)" $$file; done

clean:
	rm -f $(HTML) $(XML) $(OPENRING_FOOTER) $(RSS_FEED) blog/preview.md