home · contact · privacy
1bd4dd13115f32556b77e065b223e8e488eb584e
[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 # Iterate through entries sorted by lastmod of their source files, write entry.
19 # FIXME: This ls parsing is a bad way to loop through the sorted files. Besides,
20 # $'\0' is a bashism.
21 first_run=0
22 files=`ls -1t *.rst *.md | tr '\n' $'\0'`
23 oldIFS="$IFS"
24 IFS=$'\0'
25 for file in $files; do
26   if [ "$first_run" -lt "1" ]; then
27     IFS="$oldIFS"
28     first_run=1
29   fi
30   intermediate_file="${file%.*}.intermediate"
31   html_file="${file%.*}.html"
32   redo-ifchange "$intermediate_file"
33   redo-ifchange "$html_file"
34   title_html=`cat "$intermediate_file" | head -1`
35   html_file_escaped=`escape_url "$html_file"`
36   printf "<li><a href=\"%s\" />%s</a></li>\n" "$html_file_escaped" "$title_html"
37 done
38
39 printf "</ul>\n</body>\n</html>"