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