blob: 767b083719ccf810a39eacb48d64bcbef3a508d4 (
plain)
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
|
#!/usr/bin/env bash
# create a gopher rss feed
phloglink="gopher://spike.nagatha.fr/0/phlog"
description="Phil's Phlog"
rsslink=gopher://spike.nagatha.fr/0/phlog/rss.xml
filename=$HOME/src/gopher/phlog/rss.xml
phlogroot=$HOME/src/gopher/phlog
builddate=$(date --iso-8601=ns)
buildyear=$(date +%Y)
# Build RSS header & footer
build_header () {
echo "<?xml version='1.0' encoding='UTF-8' ?>
<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>" > ~/header
echo "<channel>
<title>Phil's Phlog</title>
<link>gopher://spike.nagatha.fr/1/phlog</link>
<atom:link href='$rsslink' rel='self' type='application/rss+xml' />
<language>en-us</language>
<copyright>©$buildyear Philip A. Wittamore</copyright>
<copyright>© $buildyear Philip A. Wittamore - All Rights Reserved</copyright>
<lastBuildDate>$builddate</lastBuildDate>
<description>A Gopher phlog from Brittany, France</description>
" >> ~/header
}
build_footer () {
echo "
</channel>
</rss>
" >> ~/footer
}
build_item () {
echo "<item>
<title>$title</title>
<pubDate>$postdate</pubDate>
<link>$linkadd</link>
<guid>$linkadd</guid>
<description>$description</description>
</item>" >> ~/feed
}
build_xml_file () {
build_header
build_footer
cat ~/header ~/feed > ~/rss_tmp
cat ~/rss_tmp ~/footer > "$filename"
rm ~/header ~/feed ~/rss_tmp ~/footer
}
# list files and create rss.xml
if [[ -f $filename ]]; then
rm "$filename"
fi
touch "$filename"
mapfile -t dir_array < <(ls -dr */)
postNum=0
for dir in "${dir_array[@]}"; do
((postNum+=1))
post=$dir
post="${dir//\//}"
title=$(head -n1 "$post/gophermap")
postdate=$(cat "$post/gophermap" | sed -n '2p')
postname=${post##*/}
linkadd="$phloglink/$post/gophermap"
description="$(cat "$post/gophermap" | sed -n "/^$/,/^$/p" | head --lines 3) …"
build_item "$post"
done
# put it all together
build_xml_file
exit
|