home · contact · privacy
Update HTML templates.
[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     meta_file="${metadata_dir}/${file%.*}.automatic_metadata"
21     redo-ifchange "$meta_file"
22     published=$(get_creation_date_from_meta_file_nanoseconds "$meta_file")
23     snippet_file="${metadata_dir}/${file%.*}.index_snippet"
24     redo-ifchange "$snippet_file"
25     ln -s "$srcdir/$snippet_file" "./${tmp_snippets_dir}/${published}"
26   fi
27 done
28
29 # Write link list.
30 for file in ./${tmp_snippets_dir}/*; do
31   if [ -e "$file" ]; then
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   fi
36 done
37 if [ -e "./${tmp_snippets_dir}/list" ]; then
38   list=$(cat ./${tmp_snippets_dir}/list | prep_sed)
39 fi
40 rm -rf "${tmp_snippets_dir}"
41
42 # Put data into template.
43 template=$(cat "$template_file")
44 printf "%s" "$template" | \
45 sed 's/%TITLE%/'"$title"'/g' | \
46 sed 's/%LIST%/'"$list"'/g' | \
47 tr '\a' '%'