-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathMakefile
More file actions
210 lines (202 loc) · 6.05 KB
/
Makefile
File metadata and controls
210 lines (202 loc) · 6.05 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# Bedrock Linux Website Generator Makefile
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
#
# Copyright (c) 2012-2020 Daniel Thau <danthau@bedrocklinux.org>
OBJECTS=$(shell find markdown/ -type f ! -name "header" ! -name "footer" ! -name "*.nav" | sed -e 's/^markdown/html/g' -e 's/[.]md/.html/g') html/atom.xml
all: check-dependencies symlinks $(OBJECTS)
clean:
rm -rf ./html/*
check-dependencies:
@ command -v markdown >/dev/null 2>&1 || (echo "Missing dependency: markdown" ; false)
# make resolves symlinks; can't just have them be targets directly.
symlinks:
@ if [ "$$(readlink html/0.7/compatibility-and-workarounds.html)" != "feature-compatibility.html" ]; then \
echo rm -f html/0.7/compatibility-and-workarounds.html; \
rm -f html/0.7/compatibility-and-workarounds.html; \
fi
@ if [ "$$(readlink html/0.7/distro-support.html)" != "distro-compatibility.html" ]; then \
echo rm -f html/0.7/distro-support.html; \
rm -f html/0.7/distro-support.html; \
fi
@ if ! [ -h html/0.7/compatibility-and-workarounds.html ]; then \
mkdir -p html/0.7; \
echo ln -s feature-compatibility.html html/0.7/compatibility-and-workarounds.html; \
ln -s feature-compatibility.html html/0.7/compatibility-and-workarounds.html; \
fi
@ if ! [ -h html/0.7/distro-support.html ]; then \
mkdir -p html/0.7; \
echo ln -s distro-compatibility.html html/0.7/distro-support.html; \
ln -s distro-compatibility.html html/0.7/distro-support.html; \
fi
# Generate atom.xml
html/atom.xml: html/news.html
@ echo "Creating $@"
@ awk -F'"' ' \
BEGIN { \
while ((getline < "html/news.html") > 0) { \
if (last_update == "" && /<p><small>[0-9-]*<\/small><\/p>/) { \
gsub(/[^0-9-]/, ""); \
last_update = $$0; \
continue \
} \
if (/<h2 id=/) { \
count++ \
} \
} \
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; \
print ""; \
print "<feed xmlns=\"http://www.w3.org/2005/Atom\">"; \
print ""; \
print "\t<title>Bedrock Linux</title>"; \
print "\t<link href=\"http://bedrocklinux.org/atom.xml\" rel=\"self\" />"; \
print "\t<link href=\"http://bedrocklinux.org/\"/>"; \
print "\t<id>http://bedrocklinux.org/atom.xml</id>"; \
print "\t<updated>" last_update "</updated>"; \
print ""; \
} \
/^<h2 id=/ || /^<\/section>$$/ { \
url = "http://bedrocklinux.org/news.html#"$$2; \
title = substr($$3, 2, length($$3)-6); \
if (in_content) { \
print "\t\t</content>"; \
print "\t</entry>" \
} \
in_content=0 \
} \
!/^$$/ && in_content { \
gsub(/</, "\\<", $$0); \
gsub(/>/, "\\>", $$0); \
print "\t\t\t" $$0 \
} \
/^<p><small>[0-9-]*<\/small><\/p>/ { \
date = substr($$0, 11, 10); \
print "\t<entry>"; \
print "\t\t<id>http://bedrocklinux.org/news/" (count--) "</id>"; \
print "\t\t<title>" title "</title>"; \
print "\t\t<link href=\"" url "\"/>"; \
print "\t\t<updated>" date "</updated>"; \
print "\t\t<content type=\"html\">"; \
in_content = 1 \
} \
END { \
print "</feed>" \
} \
' html/news.html > html/atom.xml
# Translate markdown
html/%.html: markdown/%.md markdown/header markdown/footer markdown/*.nav markdown/*/*.nav
@ echo "Creating $@"
@ # Ensure containing directory exists
@ mkdir -p $$(dirname $@)
@ # Create header
@ sed \
-e "s@TITLEGOESHERE@$$(sed -n 's/^Title:[ ]\+//p' $<)@" \
-e "s@RELATIVEPATH@$$(dirname $@ | sed -e 's/[^\/]\+/../g' -e 's/^.//')@" \
markdown/header > $@
@ # Create naviation bar
@ markdown $$(dirname $<)/$$(sed -n 's/^Nav:[ ]\+//p' $<) | sed 's/<ul>/<ul id=nav>/' >> $@
@ cat markdown/footer >> $@
@ echo '<section>' >> $@
@ # cut the non-standard-markdown Title: and Nav: lines
@ sed '1,2d' $< |\
# Create table of contents \
awk ' \
$$0 == "TableOfContents" { \
while ((getline < "$<") > 0) { \
if (!/^#.*{id=/) { \
continue \
} \
split($$0, a, "} "); \
title = a[2]; \
split($$0, a, "\""); \
link = a[2]; \
indent = substr($$0, 3); \
gsub(/[^#]/, "", indent); \
gsub(/#/, "\t", indent); \
printf "%s- [%s](#%s)\n", indent, title, link \
} \
next \
} \
1 \
' |\
# Convert markdown to html \
markdown |\
# Create tables \
awk '\
/^<p>[|]/ { \
in_table = 1; \
print "<p><table><tr>"; \
len = split($$0, a, / *[|] */); \
for (i = 2; i < len; i++) { \
print "<th>"a[i]"</th>" \
} \
print "</tr>"; \
next \
} \
/^[|]/ && in_table { \
print "<tr>"; \
len = split($$0, a, / *[|] */); \
for (i = 2; i < len; i++) { \
if (a[i] ~ /[0-9]#/) { \
span=a[i]; \
sub(/^[0-9]*#/, "", a[i]); \
sub(/#.*/, "", span); \
print "<td rowspan=\""span"\">"a[i]"</td>" \
} else { \
print "<td align=\"center\">"a[i]"</td>" \
} \
} \
print "</tr>"; \
next \
} \
in_table { \
print "</table>"; \
in_table = 0 \
} \
{ \
print \
} \
END { \
if (in_table) { \
print "</table>" \
} \
} \
' |\
# First unordered-list entry indicates class for entire list \
awk -F"[{}]" ' \
$$0 == "<ul>" { \
getline; \
if (/^<li>{/) { \
printf "<ul %s>\n", $$2 \
} else { \
printf "<ul>\n%s\n", $$0 \
} \
next \
} \
1 \
' |\
# Substitutions for inline classes \
# Remove markdown default of <code> automatically nested in <pre> \
sed \
-e 's,~(,<code class="changethis">,g' \
-e 's,~),</code>,g' \
-e 's,~{,<code class="keyword">,g' \
-e 's,~},</code>,g' \
-e 's,~#,<span class="comment">,g' \
-e 's,~+,<span class="distro">,g' \
-e 's,~%,<span class="okay">,g' \
-e 's,~^,<span class="warn">,g' \
-e 's,~!,<span class="alert">,g' \
-e 's,~x,</span>,g' \
-e 's/<\([^>]\+\)>{\([^}]\+\)}[ ]\+/<\1 \2>/g' \
-e 's,<pre><code,<pre,g' \
-e 's,</code></pre>,</pre>,g' |\
cat >> $@
@ echo '</section>' >> $@
# If the source isn't markdown, copy it as-is
html/%: markdown/%
@ echo "Copying $@"
@ mkdir -p $$(dirname $@)
@ cp -a $< $@