-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
158 lines (128 loc) · 3.46 KB
/
Makefile
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# Content
AUTHOR_NAME = "Jonathan Frederick"
AUTHOR_EMAIL = "[email protected]"
SITE_TITLE = "Jonathan Frederick's Blog"
SITE_TAGLINE = "Open Source Blog"
LOCALE = "en_US.utf-8"
POSTS_PER_PAGE = 10
POSTS_PER_PAGE_ATOM = 10
POSTS = \
libvirt-cluster \
blogsandblogc \
$(NULL)
PAGES = \
about \
$(NULL)
ASSETS = \
assets/style.css \
assets/images/tile.png \
assets/images/favicon.png \
$(NULL)
# Arguments
BLOGC ?= $(shell which blogc)
BLOGC_RUNSERVER ?= $(shell which blogc-runserver 2> /dev/null)
ENTR ?= $(shell which entr 2> /dev/null)
MKDIR ?= $(shell which mkdir)
CP ?= $(shell which cp)
BLOGC_RUNSERVER_HOST ?= 0.0.0.0
BLOGC_RUNSERVER_PORT ?= 8080
OUTPUT_DIR ?= _build
BASE_DOMAIN ?= https://blog.doublej472.com
BASE_URL ?=
DATE_FORMAT = "%b %d, %Y, %I:%M %p PST"
DATE_FORMAT_ATOM = "%Y-%m-%dT%H:%M:%SZ"
BLOGC_COMMAND = \
LC_ALL=$(LOCALE) \
$(BLOGC) \
-D AUTHOR_NAME=$(AUTHOR_NAME) \
-D AUTHOR_EMAIL=$(AUTHOR_EMAIL) \
-D SITE_TITLE=$(SITE_TITLE) \
-D SITE_TAGLINE=$(SITE_TAGLINE) \
-D BASE_DOMAIN=$(BASE_DOMAIN) \
-D BASE_URL=$(BASE_URL) \
$(NULL)
# Rules
POSTS_LIST = $(addprefix content/post/, $(addsuffix .txt, $(POSTS)))
PAGES_LIST = $(addprefix content/, $(addsuffix .txt, $(PAGES)))
LAST_PAGE = $(shell $(BLOGC_COMMAND) \
-D FILTER_PAGE=1 \
-D FILTER_PER_PAGE=$(POSTS_PER_PAGE) \
-p LAST_PAGE \
-l \
$(POSTS_LIST))
ALL_LIST = \
$(POSTS_LIST) \
$(PAGES_LIST) \
$(ASSETS) \
templates/main.tmpl \
templates/atom.tmpl \
Makefile \
$(NULL)
all: \
$(OUTPUT_DIR)/index.html \
$(OUTPUT_DIR)/atom.xml \
$(addprefix $(OUTPUT_DIR)/, $(ASSETS)) \
$(addprefix $(OUTPUT_DIR)/post/, $(addsuffix /index.html, $(POSTS))) \
$(addprefix $(OUTPUT_DIR)/, $(addsuffix /index.html, $(PAGES))) \
$(addprefix $(OUTPUT_DIR)/page/, $(addsuffix /index.html, \
$(shell for i in $(shell seq 1 $(LAST_PAGE)); do echo $$i; done)))
$(OUTPUT_DIR)/index.html: $(POSTS_LIST) templates/main.tmpl Makefile
$(BLOGC_COMMAND) \
-D DATE_FORMAT=$(DATE_FORMAT) \
-D FILTER_PAGE=1 \
-D FILTER_PER_PAGE=$(POSTS_PER_PAGE) \
-D MENU=blog \
-l \
-o $@ \
-t templates/main.tmpl \
$(POSTS_LIST)
$(OUTPUT_DIR)/page/%/index.html: $(POSTS_LIST) templates/main.tmpl Makefile
$(BLOGC_COMMAND) \
-D DATE_FORMAT=$(DATE_FORMAT) \
-D FILTER_PAGE=$(shell echo $@ | sed -e 's,^$(OUTPUT_DIR)/page/,,' -e 's,/index\.html$$,,')\
-D FILTER_PER_PAGE=$(POSTS_PER_PAGE) \
-D MENU=blog \
-l \
-o $@ \
-t templates/main.tmpl \
$(POSTS_LIST)
$(OUTPUT_DIR)/atom.xml: $(POSTS_LIST) templates/atom.tmpl Makefile
$(BLOGC_COMMAND) \
-D DATE_FORMAT=$(DATE_FORMAT_ATOM) \
-D FILTER_PAGE=1 \
-D FILTER_PER_PAGE=$(POSTS_PER_PAGE_ATOM) \
-l \
-o $@ \
-t templates/atom.tmpl \
$(POSTS_LIST)
IS_POST = 0
$(OUTPUT_DIR)/about/index.html: MENU = about
$(OUTPUT_DIR)/post/%/index.html: MENU = blog
$(OUTPUT_DIR)/post/%/index.html: IS_POST = 1
$(OUTPUT_DIR)/%/index.html: content/%.txt templates/main.tmpl Makefile
$(BLOGC_COMMAND) \
-D DATE_FORMAT=$(DATE_FORMAT) \
-D MENU=$(MENU) \
$(shell test "$(IS_POST)" -eq 1 && echo -D IS_POST=1) \
-o $@ \
-t templates/main.tmpl \
$<
$(OUTPUT_DIR)/assets/%: assets/% Makefile
$(MKDIR) -p $(dir $@) && \
$(CP) $< $@
ifneq ($(BLOGC_RUNSERVER),)
.PHONY: serve
serve: all
$(BLOGC_RUNSERVER) \
-t $(BLOGC_RUNSERVER_HOST) \
-p $(BLOGC_RUNSERVER_PORT) \
$(OUTPUT_DIR)
endif
ifneq ($(ENTR),)
.PHONY: reload
reload:
for i in $(ALL_LIST); do echo $$i; done | $(ENTR) -r $(MAKE) serve
endif
clean:
rm -rf "$(OUTPUT_DIR)"
.PHONY: all clean