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
23 feed_gen_date=$(stat -c%Y "${uuid_file}")
25 # Write majority of feed head.
27 <?xml version="1.0" encoding="utf-8"?>
28 <feed xmlns="http://www.w3.org/2005/Atom">
30 printf "<link href=\"%s\" />\n" "$basepath"
31 printf "<link href=\"%sfeed.xml\" rel=\"self\" />\n" "$basepath"
32 printf "<title type=\"html\">%s</title>\n" "$title"
33 printf "<author><name>%s</name></author>\n" "$author"
34 printf "<id>urn:uuid:%s</id>\n" "$uuid"
36 # Generate feed entry snippets.
37 mkdir -p "$tmp_snippets_dir"
38 for file in ./*.rst ./*.md; do
39 if [ -e "$file" ]; then
40 uuid_file="${metadata_dir}/${file%.*}.uuid"
41 redo-ifchange "$uuid_file"
42 published=$(stat -c%Y "${uuid_file}")
43 snippet_file=./${metadata_dir}/"${file%.*}.feed_snippet"
44 redo-ifchange "$snippet_file"
45 ln -s "$srcdir/$snippet_file" "./${tmp_snippets_dir}/${published}"
49 # Derive feed modification date from snippets. Fallback to uuid file mod date.
50 n_snippet_files=`ls -1 ./${metadata_dir}/*.feed_snippet 2>/dev/null | wc -l`
51 if [ $n_snippet_files != 0 ]
53 mod_dates=$(grep -hE "^<updated>" ./${metadata_dir}/*.feed_snippet | sed -E 's/<.?updated>//g')
55 last_mod_unix=$feed_gen_date
56 for date in $mod_dates; do
57 date_unix=$(date -u "+%s" -d "${date}")
58 if [ "$date_unix" -gt "$last_mod_unix" ]; then
59 last_mod_unix=$date_unix
62 last_mod_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "@${last_mod_unix}"`
63 printf "<updated>%s</updated>\n\n" "$last_mod_rfc3339"
66 for file in ./${tmp_snippets_dir}/*; do
67 if [ -e "$file" ]; then
72 rm -rf "$tmp_snippets_dir"