7 intermediate_file="${file%.*}.intermediate"
8 htmlfile=`escape_url "${file%.*}.html"`
9 redo-ifchange "$uuid_file"
10 redo-ifchange "$intermediate_file"
11 lastmod=`stat -c%y "$file"`
12 lastmod_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "$lastmod"`
13 title=`read_and_escape_file "$intermediate_file" | head -1`
14 uuid=`read_and_escape_file "$uuid_file" | head -1`
15 body=`read_and_escape_file "$intermediate_file" | sed 1d`
16 published_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "${published}"`
18 printf "<title type=\"html\">%s</title>\n" "$title"
19 printf "<id>urn:uuid:%s</id>\n" "$uuid"
20 printf "<updated>%s</updated>\n" "$lastmod_rfc3339"
21 printf "<published>%s</published>\n" "$published_rfc3339"
22 printf "<link href=\"%s%s\" />\n" "$basepath" "${htmlfile#\./}"
23 printf "<content type=\"html\">\n%s\n</content>\n" "$body"
27 # Pull in global dependencies.
30 author_file=author.meta
33 redo-ifchange "$url_file"
34 redo-ifchange "$author_file"
35 redo-ifchange "$uuid_file"
36 redo-ifchange "$title_file"
38 # Build some variables. XML-escape even file contents that should not contain
39 # dangerous characters, just to avoid any XML trouble.
40 base_url=`cat "$url_file" | head -1`
41 url_protocol=`echo $base_url | cut -d ':' -f 1`
42 url_basepath=`echo $base_url | cut -d '/' -f 3-`
43 url_basepath_escaped=`escape_url "$url_basepath"`
44 basepath="$url_protocol""://""$url_basepath_escaped"
45 title=`read_and_escape_file "$title_file" | head -1`
46 author=`read_and_escape_file "$author_file" | head -1`
47 uuid=`read_and_escape_file "$uuid_file" | head -1`
49 # Write majority of feed head.
51 <?xml version="1.0" encoding="utf-8"?>
52 <feed xmlns="http://www.w3.org/2005/Atom">
54 printf "<link href=\"%s\" />\n" "$basepath"
55 printf "<link href=\"%sfeed.xml\" rel=\"self\" />\n" "$basepath"
56 printf "<title type=\"html\">%s</title>\n" "$title"
57 printf "<author><name>%s</name></author>\n" "$author"
58 printf "<id>urn:uuid:%s</id>\n" "$uuid"
60 # Generate feed entry snippets.
61 mkdir -p feed_snippets
62 for file in ./*.rst ./*.md; do
63 if [ -e "$file" ]; then
64 uuid_file="${file%.*}.uuid"
65 redo-ifchange "$uuid_file"
66 published=`stat -c%y "${uuid_file}"`
67 published_unix=$(date -u "+%s%N" -d "${published}")
68 entry=$(build_entry "${file}" "${uuid_file}" "${published}")
69 echo "${entry}" > ./feed_snippets/${published_unix}
73 # Derive feed modification date from snippets.
74 mod_dates=$(grep -hE "^<updated>" ./feed_snippets/* | sed -E 's/<.?updated>//g')
76 for date in $mod_dates; do
77 date_unix=$(date -u "+%s" -d "${date}")
78 if [ "$date_unix" -gt "$last_mod_unix" ]; then
79 last_mod_unix=$date_unix
82 lastmod_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "@${last_mod_unix}"`
83 printf "<updated>%s</updated>\n\n" "$lastmod_rfc3339"
86 for file in ./feed_snippets/*; do