summaryrefslogtreecommitdiff
path: root/strus/create_xml.sh
blob: 4ef5c5a5e46fc8e5b3e984e6f4b79c6eca8b2ade (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
#!/bin/sh

cat <<EOF
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<posts>
EOF

if test `uname -s` = 'Darwin'; then
	SED=gsed
else
	SED=sed
fi

for file in `find ../content/ -name '*.md'`; do
	echo "$file.." 1>&2
	slug=`echo $file | $SED 's@../content@@g' | $SED 's@/_index.md$@@g' | $SED 's@.md$@@g'`
	if test "x$slug" = "x"; then
		slug="/"
	fi
	
	slug=`echo $slug | sed 's@^//@/@g'`
	
	awk 'BEGIN { i = 0 } /\+\+\+/{x="F"++i;}{print > x;}' $file >/dev/null 2>&1
	
	if test ! -f F1 -a -f F2; then
		continue
	fi
	
	tail -n +2 F1 > meta.toml
	tail -n +3 F2 > body.md
	
	$SED -i 's/\&/&amp;/g' meta.toml
	$SED -i 's/</\&lt;/g' meta.toml
	$SED -i 's/>/\&gt;/g' meta.toml
	$SED -i 's/\&/&amp;/g' body.md
	$SED -i 's/</\&lt;/g' body.md
	$SED -i 's/>/\&gt;/g' body.md
	
	remarshal -if toml -of json meta.toml > meta.json
	pandoc -f markdown -t docbook body.md > body.xml
	
	echo "<post>"
	echo "<slug>$slug</slug>"
	echo "<filename>$file</filename>"
	echo "<meta>"
	cat meta.json
	echo "</meta>"
	echo "<body>"
	cat body.xml
	echo "</body>"
	echo "</post>"

	rm -f meta.* body.* F1 F2
done

cat <<EOF
</posts>
EOF