-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmake_feed
More file actions
executable file
·104 lines (89 loc) · 2.11 KB
/
Copy pathmake_feed
File metadata and controls
executable file
·104 lines (89 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/sh
# Barebones Atom feed generator for news items.
# Extracts the first line beginning with hashes as the entry title.
set -e
METAFILE="en/_meta/atom"
HOMEPAGE="https://liballeg.org/"
rfc3339_date () {
# Validators say that T must be used as date-time separator.
date --rfc-3339=seconds "$@" | tr ' ' 'T'
}
# Reverse any series of filenames containing dates.
revdatesort () {(
acc=
for x in "$@"
do
case "$x" in
*[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]*)
acc="$x $acc"
;;
*)
echo "$acc"
acc=
echo "$x"
;;
esac
done
echo "$acc"
)}
emit_top () {
date=$1
cat <<- EOF
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Allegro news</title>
<link href="$HOMEPAGE"/>
<link rel="self" href="${HOMEPAGE}feed_atom.xml"/>
<updated>$date</updated>
<id>urn:uuid:661257c2-82a0-4510-b2be-0f6b010807b9</id>
EOF
}
emit_entry () {(
file=$1
uuid=$( grep "^$file uuid=" $METAFILE | cut -d= -f2- )
date=$( grep "^$file date=" $METAFILE | cut -d= -f2- )
if test -z "$uuid"
then
uuid="$( uuidgen )"
date=$( rfc3339_date -r $file )
echo "$file uuid=$uuid" >> $METAFILE
echo "$file date=$date" >> $METAFILE
fi
title=$( grep '^#\+ ' $file | head -n 1 )
title=${title#* } # remove leading whitespace
title=${title#????-??-?? - } # remove leading date
cat <<- EOF
<entry>
<title>$title</title>
<author><name>Allegro developers</name></author>
<link href="$HOMEPAGE"/>
<id>urn:uuid:$uuid</id>
<updated>$date</updated>
</entry>
EOF
)}
emit_bottom () {
cat <<- EOF
</feed>
EOF
}
get_first_date() {
file="$1"
date=$( grep "^$file date=" $METAFILE | cut -d= -f2- )
if test -z "$date"
then
date=$( rfc3339_date -r ${@%% *} )
fi
echo "$date"
}
all_files=$( revdatesort "$@" )
first_date=$( get_first_date ${all_files%% *} )
>> $METAFILE
emit_top $first_date
for file in ${all_files}
do
emit_entry $file
done
emit_bottom
# The <<- syntax strips tabs, so use tabs instead of spaces.
# vim: set ts=8 sts=8 sw=8 noet: