home · contact · privacy
Add HTML templating, extend tests.
[redo-blog] / processor / index.html.do
1 #!/bin/sh
2
3 # Pull in global dependencies.
4 . ./helpers.sh
5 metadata_dir=metadata
6 srcdir=`pwd`
7 title_file="$metadata_dir"/title
8 redo-ifchange "$title_file"
9 template_file="${metadata_dir}"/index.tmpl
10 redo-ifchange "$template_file"
11
12 # Build blog title.
13 title=$(read_and_escape_file "$title_file" | head -1 | prep_sed)
14
15 # Generate link list entries.
16 tmp_snippets_dir=.tmp_index_snippets
17 mkdir -p "$tmp_snippets_dir"
18 for file in ./*.rst ./*.md; do
19   if [ -e "$file" ]; then
20     uuid_file="${metadata_dir}/${file%.*}.uuid"
21     redo-ifchange "$uuid_file"
22     published=`stat -c%y "${uuid_file}"`
23     published_unix=$(date -u "+%s%N" -d "${published}")
24     snippet_file="${metadata_dir}/${file%.*}.index_snippet"
25     redo-ifchange "$snippet_file"
26     ln -s "$srcdir/$snippet_file" "./${tmp_snippets_dir}/${published_unix}"
27   fi
28 done
29
30 # Write link list.
31 for file in ./${tmp_snippets_dir}/*; do
32   touch ./${tmp_snippets_dir}/list
33   cat "$file" ./${tmp_snippets_dir}/list > ./${tmp_snippets_dir}/tmp
34   mv ./${tmp_snippets_dir}/tmp ./${tmp_snippets_dir}/list
35 done
36 if [ -e "./${tmp_snippets_dir}/list" ]; then
37   list=$(cat ./${tmp_snippets_dir}/list | prep_sed)
38 fi
39 rm -rf "${tmp_snippets_dir}"
40
41 # Put data into template.
42 template=$(cat "$template_file")
43 printf "%s" "$template" | \
44 sed 's/%TITLE%/'"$title"'/g' | \
45 sed 's/%LIST%/'"$list"'/g' | \
46 tr '\a' '%'