home · contact · privacy
Move snippet generation for index/feed into separate .do files.
[redo-blog] / processor / index.html.do
1 #!/bin/sh
2
3 # Pull in global dependencies.
4 . ./helpers.sh
5 srcdir=`pwd`
6 title_file=title.meta
7 redo-ifchange "$title_file"
8
9 # Write index head.
10 cat << EOF
11 <!DOCTYPE html>
12 <html>
13 <head>
14 EOF
15 blog_title=`read_and_escape_file "$title_file" | head -1`
16 printf "<title>%s</title>\n</head>\n<body>\n" "$blog_title"
17 printf "<h1>%s</h1>\n<ul>\n" "$blog_title"
18
19 # Generate link list entries.
20 mkdir -p index_snippets
21 for file in ./*.rst ./*.md; do
22   if [ -e "$file" ]; then
23     uuid_file="${file%.*}.uuid"
24     redo-ifchange "$uuid_file"
25     published=`stat -c%y "${uuid_file}"`
26     published_unix=$(date -u "+%s%N" -d "${published}")
27     snippet_file="${file%.*}.index_snippet"
28     redo-ifchange "$snippet_file"
29     ln -s "$srcdir/$snippet_file" "./index_snippets/${published_unix}"
30   fi
31 done
32
33 # Write link list.
34 for file in ./index_snippets/*; do
35   touch ./index_snippets/list
36   cat "$file" ./index_snippets/list > ./index_snippets/tmp
37   mv ./index_snippets/tmp ./index_snippets/list
38 done
39 if [ -e "./index_snippets/list" ]; then
40   cat ./index_snippets/list
41 fi
42 rm -rf index_snippets
43
44 # Write index footer.
45 printf "</ul>\n</body>\n</html>"