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