home · contact · privacy
Move work so far into repo.
[redo-blog] / index.html.do
1 #!/bin/sh
2
3 # Pull in global dependencies.
4 . ./helpers.sh
5 redo-ifchange title
6
7 # Write index head.
8 cat << EOF
9 <!DOCTYPE html>
10 <html>
11 <head>
12 EOF
13 blog_title=`read_and_escape_file title | head -1`
14 printf "<title>%s</title>\n</head>\n<body>\n" "$blog_title"
15 printf "<h1>%s</h1>\n<ul>\n" "$blog_title"
16
17 # Iterate through entries sorted by lastmod of their source files, write entry
18 # list. 
19 first_run=0
20 files=`ls -1t *.rst *.md | tr '\n' $'\0'`
21 oldIFS="$IFS"
22 IFS=$'\0'
23 for file in $files; do
24   if [ "$first_run" -lt "1" ]; then
25     IFS="$oldIFS"
26     first_run=1
27   fi
28   intermediate_file="${file%.*}.intermediate"
29   html_file="${file%.*}.html"
30   redo-ifchange "$intermediate_file"
31   redo-ifchange "$html_file"
32   title_html=`cat "$intermediate_file" | head -1`
33   html_file_escaped=`escape_url "$html_file"`
34   printf "<li><a href=\"%s\" />%s</a></li>\n" "$html_file_escaped" "$title_html"
35 done
36
37 printf "</ul>\n</body>\n</html>"