home · contact · privacy
Add uuid.meta test.
[redo-blog] / processor / feed.xml.do
1 #!/bin/sh
2
3 # Pull in global dependencies.
4 . ./helpers.sh
5 url_file=url.meta
6 author_file=author.meta
7 uuid_file=uuid.meta
8 title_file=title.meta
9 redo-ifchange "$url_file"
10 redo-ifchange "$author_file"
11 redo-ifchange "$uuid_file"
12 redo-ifchange "$title_file"
13
14 # Build some variables. XML-escape even file contents that should not contain
15 # dangerous characters, just to avoid any XML trouble.
16 base_url=`cat "$url_file" | head -1`
17 url_protocol=`echo $base_url | cut -d ':' -f 1`
18 url_basepath=`echo $base_url | cut -d '/' -f 3-`
19 url_basepath_escaped=`escape_url "$url_basepath"`
20 basepath="$url_protocol""://""$url_basepath_escaped"
21 title=`read_and_escape_file "$title_file" | head -1`
22 author=`read_and_escape_file "$author_file" | head -1`
23 uuid=`read_and_escape_file "$uuid_file" | head -1`
24
25 # Write majority of feed head.
26 cat << EOF
27 <?xml version="1.0" encoding="utf-8"?>
28 <feed xmlns="http://www.w3.org/2005/Atom">
29 EOF
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"
35
36 # Iterate through most recent entries (go by lastmod date of source files) to
37 # build feed head "updated" element, and individual entries.
38 first_run=0
39 files=`ls -1t *.rst *.md | head -10 | tr '\n' $'\0'`
40 oldIFS="$IFS"
41 IFS=$'\0'
42 for file in $files; do
43   lastmod=`stat -c%y "$file"`
44   lastmod_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "$lastmod"`
45   if [ "$first_run" -lt "1" ]; then
46     IFS="$oldIFS"
47     printf "<updated>%s</updated>\n\n" "$lastmod_rfc3339" 
48     first_run=1
49   fi
50
51   # Build some variables and dependencies.
52   intermediate_file="${file%.*}.intermediate"
53   htmlfile=`escape_url "${file%.*}.html"`
54   uuid_file="${file%.*}.uuid"
55   redo-ifchange "$intermediate_file"
56   redo-ifchange "$uuid_file"
57   title=`read_and_escape_file "$intermediate_file" | head -1`
58   uuid=`read_and_escape_file "$uuid_file" | head -1`
59   body=`read_and_escape_file "$intermediate_file" | sed 1d`
60   published=`stat -c%y "$uuid_file"`
61   published_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "$published"`
62
63   # Write entry.
64   printf "<entry>\n"
65   printf "<title type=\"html\">%s</title>\n" "$title"
66   printf "<id>urn:uuid:%s</id>\n" "$uuid" 
67   printf "<updated>%s</updated>\n" "$lastmod_rfc3339" 
68   printf "<published>%s</published>\n" "$published_rfc3339" 
69   printf "<link href=\"%s%s\" />\n" "$basepath" "$htmlfile"
70   printf "<content type=\"html\">\n%s\n</content>\n" "$body"
71   printf "</entry>\n\n"
72 done
73
74 printf "</feed>"