home · contact · privacy
Add captcha files support.
[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
14 meta_file="${metadata_dir}/${1%.html}.automatic_metadata"
15 redo-ifchange "$meta_file"
16 intermediate_file="${metadata_dir}/${1%.html}.intermediate"
17 redo-ifchange "$intermediate_file"
18 title_file="${metadata_dir}"/title
19 redo-ifchange "$title_file" 
20 article_tmpl_file="${metadata_dir}"/article.tmpl
21 redo-ifchange "$article_tmpl_file"
22 linkback_tmpl_file="${metadata_dir}"/linkback.tmpl
23 redo-ifchange "$linkback_tmpl_file"
24 replies_file="${1%.html}.links"
25 redo-ifchange "$replies_file"
26 captcha_file="$captchas_dir/${1%.html}"
27 redo-ifchange "$captcha_file"
28
29 # Build entry data.
30 blog_title=$(read_and_escape_file "$title_file" | head -1 | prep_sed)
31 title_html=$(cat "$intermediate_file" | head -1)
32 title_plaintext=`echo "$title_html" | html2text`
33 title_html=$(printf "%s" "$title_html" | prep_sed)
34 title_plaintext=$(escape_html "$title_plaintext" | prep_sed)
35 body=$(cat "$intermediate_file" | sed 1d | prep_sed)
36 datetime_created_unix=$(get_creation_date_from_meta_file_seconds "$meta_file")
37 date_created=$(date -u "+%Y-%m-%d" -d "@${datetime_created_unix}")
38 datetime_lastmod_unix=$(get_lastmod_date_from_meta_file "$meta_file")
39 date_updated=$(date -u "+%Y-%m-%d" -d "@${datetime_lastmod_unix}")
40 replies=$(while read line; do prep_url "$line"; done < "$replies_file")
41
42 # Put data into template.
43 template=$(cat "$article_tmpl_file")
44 printf "%s" "$template" | \
45 sed 's/%BLOG_TITLE%/'"$blog_title"'/g' | \
46 sed 's/%ARTICLE_TITLE_ESCAPED%/'"$title_plaintext"'/g' | \
47 sed 's/%ARTICLE_TITLE_HTML%/'"$title_html"'/g' | \
48 sed 's/%DATE_CREATED%/'"$date_created"'/g' | \
49 sed 's/%DATE_UPDATED%/'"$date_updated"'/g' | \
50 sed 's/%BODY%/'"$body"'/g' | \
51 sed 's/%LINKBACKS%/'"$replies"'/g' | \
52 tr '\a' '%'