3 # Pull in global dependencies.
6 author_file="$metadata_dir"/author
7 uuid_file="$metadata_dir"/uuid
8 title_file="$metadata_dir"/title
9 url_file="$metadata_dir"/url
10 redo-ifchange "$url_file"
11 redo-ifchange "$author_file"
12 redo-ifchange "$uuid_file"
13 redo-ifchange "$title_file"
15 # Build some variables. XML-escape even file contents that should not contain
16 # dangerous characters, just to avoid any XML trouble.
18 basepath=$(get_basepath "${metadata_dir}/")
19 title=`read_and_escape_file "$title_file" | head -1`
20 author=`read_and_escape_file "$author_file" | head -1`
21 uuid=`read_and_escape_file "$uuid_file" | head -1`
22 tmp_snippets_dir=.tmp_feed_snippets
24 # Write majority of feed head.
26 <?xml version="1.0" encoding="utf-8"?>
27 <feed xmlns="http://www.w3.org/2005/Atom">
29 printf "<link href=\"%s\" />\n" "$basepath"
30 printf "<link href=\"%sfeed.xml\" rel=\"self\" />\n" "$basepath"
31 printf "<title type=\"html\">%s</title>\n" "$title"
32 printf "<author><name>%s</name></author>\n" "$author"
33 printf "<id>urn:uuid:%s</id>\n" "$uuid"
35 # Generate feed entry snippets.
36 mkdir -p "$tmp_snippets_dir"
37 for file in ./*.rst ./*.md; do
38 if [ -e "$file" ]; then
39 uuid_file="${metadata_dir}/${file%.*}.uuid"
40 redo-ifchange "$uuid_file"
41 published=`stat -c%y "${uuid_file}"`
42 published_unix=$(date -u "+%s%N" -d "${published}")
43 snippet_file=./${metadata_dir}/"${file%.*}.feed_snippet"
44 redo-ifchange "$snippet_file"
45 ln -s "$srcdir/$snippet_file" "./${tmp_snippets_dir}/${published_unix}"
49 # Derive feed modification date from snippets.
50 mod_dates=$(grep -hE "^<updated>" ./${metadata_dir}/*.feed_snippet | sed -E 's/<.?updated>//g')
52 for date in $mod_dates; do
53 date_unix=$(date -u "+%s" -d "${date}")
54 if [ "$date_unix" -gt "$last_mod_unix" ]; then
55 last_mod_unix=$date_unix
58 lastmod_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "@${last_mod_unix}"`
59 printf "<updated>%s</updated>\n\n" "$lastmod_rfc3339"
62 for file in ./${tmp_snippets_dir}/*; do
66 rm -rf "$tmp_snippets_dir"