home · contact · privacy
31fa9cd5e24259401c9ff0332eae1639f95c8648
[redo-blog] / processor / default.html.do
1 #!/bin/sh
2
3 # Handle URL from .links file.
4 prep_url() {
5   url=$(printf "%s" "$(escape_html "$1")" | prep_sed)
6   template=$(cat "$linkback_tmpl_file")
7   printf "%s" "$template" | sed 's/%URL%/'"$url"'/g' | tr '\a' '%' | prep_sed
8 }
9
10 # Pull in global dependencies.
11 . ./helpers.sh
12 metadata_dir=metadata
13 captchas_dir=captchas/public
14 mkdir -p "$captchas_dir"
15 meta_file="${metadata_dir}/${1%.html}.automatic_metadata"
16 redo-ifchange "$meta_file"
17 intermediate_file="${metadata_dir}/${1%.html}.intermediate"
18 redo-ifchange "$intermediate_file"
19 title_file="${metadata_dir}"/title
20 redo-ifchange "$title_file" 
21 article_tmpl_file="${metadata_dir}"/article.tmpl
22 redo-ifchange "$article_tmpl_file"
23 linkback_tmpl_file="${metadata_dir}"/linkback.tmpl
24 redo-ifchange "$linkback_tmpl_file"
25 replies_file="${1%.html}.links"
26 redo-ifchange "$replies_file"
27 captcha_file="$captchas_dir/${1%.html}"
28 redo-ifchange "$captcha_file"
29
30 # Build entry data.
31 blog_title=$(read_and_escape_file "$title_file" | head -1 | prep_sed)
32 title_html=$(cat "$intermediate_file" | head -1)
33 title_plaintext=`echo "$title_html" | html2text`
34 title_html=$(printf "%s" "$title_html" | prep_sed)
35 title_plaintext=$(escape_html "$title_plaintext" | prep_sed)
36 body=$(cat "$intermediate_file" | sed 1d | prep_sed)
37 datetime_created_unix=$(get_creation_date_from_meta_file_seconds "$meta_file")
38 date_created=$(date -u "+%Y-%m-%d" -d "@${datetime_created_unix}")
39 datetime_lastmod_unix=$(get_lastmod_date_from_meta_file "$meta_file")
40 date_updated=$(date -u "+%Y-%m-%d" -d "@${datetime_lastmod_unix}")
41 replies=$(while read line; do prep_url "$line"; done < "$replies_file")
42 captcha=$(escape_html "$(cat "$captcha_file" | sed -n 2p)" | prep_sed)
43
44 # Put data into template.
45 template=$(cat "$article_tmpl_file")
46 printf "%s" "$template" | \
47 sed 's/%BLOG_TITLE%/'"$blog_title"'/g' | \
48 sed 's/%ARTICLE_TITLE_ESCAPED%/'"$title_plaintext"'/g' | \
49 sed 's/%ARTICLE_TITLE_HTML%/'"$title_html"'/g' | \
50 sed 's/%DATE_CREATED%/'"$date_created"'/g' | \
51 sed 's/%DATE_UPDATED%/'"$date_updated"'/g' | \
52 sed 's/%BODY%/'"$body"'/g' | \
53 sed 's/%LINKBACKS%/'"$replies"'/g' | \
54 sed 's/%CAPTCHA%/'"$captcha"'/g' | \
55 tr '\a' '%'