aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-11-14 01:37:13 +0000
committerng0 <ng0@n0.is>2019-11-14 01:37:13 +0000
commitad4e3f27ac49b6a253c5718faa13bea6d025fcbc (patch)
tree8a269e022c9943846b5e609f85df562b382f9021
parentc71ce2dbc82a235538645781fcbb6fb776747550 (diff)
downloadwww-ad4e3f27ac49b6a253c5718faa13bea6d025fcbc.tar.gz
www-ad4e3f27ac49b6a253c5718faa13bea6d025fcbc.zip
first version of rss generator in python.
-rw-r--r--GNUmakefile12
-rw-r--r--common/news.j24
-rwxr-xr-xmake_site.py6
-rwxr-xr-xrssg220
-rw-r--r--www.yml61
5 files changed, 56 insertions, 247 deletions
diff --git a/GNUmakefile b/GNUmakefile
index 4a1aa38a..a8ffdc3c 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -39,16 +39,14 @@ all: css locale template
39 (cd rendered/node ; $(ln) -fs about.html 397) 39 (cd rendered/node ; $(ln) -fs about.html 397)
40 ($(cp) static/moved_about.html rendered/about.html) 40 ($(cp) static/moved_about.html rendered/about.html)
41 (cd rendered ; $(ln) -fs about.html philosophy) 41 (cd rendered ; $(ln) -fs about.html philosophy)
42 (cd rendered; \ 42# (cd rendered; \
43 for lang in en de es fr it; do \ 43 for lang in en de es fr it; do \
44 $(sh) ../rssg $$lang/news/index.html 'GNUnet.org' > $$lang/news/rss.xml; \ 44 $(sh) ../rssg $$lang/news/index.html 'GNUnet.org' > $$lang/news/rss.xml; \
45 done) 45 done)
46 (cd rendered/en ; $(ln) -fs news/rss.xml rss.xml) 46 (cd rendered; \
47 (cd rendered/de ; $(ln) -fs news/rss.xml rss.xml) 47 for lang in en de es fr it; do \
48 (cd rendered/es ; $(ln) -fs news/rss.xml rss.xml) 48 $(cp) $$lang/rss.xml $$lang/news/rss.xml; \
49 (cd rendered/fr ; $(ln) -fs news/rss.xml rss.xml) 49 done)
50 (cd rendered/it ; $(ln) -fs news/rss.xml rss.xml)
51
52 50
53# Extract translateable strings from jinja2 templates. 51# Extract translateable strings from jinja2 templates.
54# Because of the local i18nfix extractor module we need 52# Because of the local i18nfix extractor module we need
diff --git a/common/news.j2 b/common/news.j2
index cdc124ba..9cdb06f2 100644
--- a/common/news.j2
+++ b/common/news.j2
@@ -16,11 +16,9 @@
16 </div> 16 </div>
17 </div> 17 </div>
18 <div class="container"> 18 <div class="container">
19 <!--BEGIN--> 19 <article id="newspost-content">
20 <article>
21 {% block body_content %}{% endblock %} 20 {% block body_content %}{% endblock %}
22 </article> 21 </article>
23 <!--END-->
24 </div> 22 </div>
25 </div> 23 </div>
26 {% include "common/footer.j2.inc" %} 24 {% include "common/footer.j2.inc" %}
diff --git a/make_site.py b/make_site.py
index 55b8510f..16a67b9a 100755
--- a/make_site.py
+++ b/make_site.py
@@ -12,7 +12,7 @@
12# 12#
13# This script runs the jinja2 templating engine on an input template-file 13# This script runs the jinja2 templating engine on an input template-file
14# using the specified locale for gettext translations, and outputs 14# using the specified locale for gettext translations, and outputs
15# the resulting (HTML) ouptut-file. 15# the resulting (HTML) output-file.
16# 16#
17# Note that the gettext files need to be prepared first. This script 17# Note that the gettext files need to be prepared first. This script
18# is thus to be invoked via the Makefile. 18# is thus to be invoked via the Makefile.
@@ -44,6 +44,10 @@ def main():
44 x = gen_site(DEBUG) 44 x = gen_site(DEBUG)
45 conf = x.load_config("www.yml") 45 conf = x.load_config("www.yml")
46 x.gen_abstract(conf, "newsposts", "abstract", "page", 1000) 46 x.gen_abstract(conf, "newsposts", "abstract", "page", 1000)
47 # for lang in conf["langs_full"]:
48 # x.gen_newspost_content(conf, "newsposts", "content", "page", lang)
49 x.gen_newspost_content(conf, "newsposts", "content", "page", "en")
50 x.gen_rss("inc", conf, env)
47 if DEBUG: 51 if DEBUG:
48 print("generating html from jinja2 templates...") 52 print("generating html from jinja2 templates...")
49 x.run("template", conf, env) 53 x.run("template", conf, env)
diff --git a/rssg b/rssg
deleted file mode 100755
index e21974f4..00000000
--- a/rssg
+++ /dev/null
@@ -1,220 +0,0 @@
1#!/bin/sh
2#
3# https://www.romanzolotarev.com/bin/rssg
4# Copyright 2018 Roman Zolotarev <hi@romanzolotarev.com>
5# Copyright 2019 ng0 <ng0@n0.is>
6#
7# Permission to use, copy, modify, and/or distribute this software for any
8# purpose with or without fee is hereby granted, provided that the above
9# copyright notice and this permission notice appear in all copies.
10#
11# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18#
19set -e
20
21# TODO: Fix date -j for GNU date.
22# TODO: Fix base url (get_url)
23# TODO: Fix link OR a in get_url
24# TODO: get_title: be more dynamic about where the title can be.
25
26main () {
27 test -n "$1" || usage
28 test -n "$2" || usage
29 test -f "$1" || no_file "$1"
30
31
32 index_file=$(readlink -f "$1")
33 test -z "${index_file##*html}" && html=$(cat "$index_file")
34 test -z "${index_file##*md}" && html=$(md_to_html "$index_file")
35 test -n "$html" || usage
36
37 base="${index_file%/*}"
38 base_url="$(echo "$html" | get_url | sed 's#\(.*\)/[^/]*#\1#')"
39
40 url=$( echo "$html" | get_url)
41
42 title="$2"
43
44 description=$( echo "$html" | get_description |
45 remove_tags |
46 remove_nbsp )
47
48 items=$( echo "$html" | get_items)
49
50 rss=$( echo "$items" |
51 render_items "$base" "$base_url" |
52 render_feed "$url" "$title" "$description")
53
54 >&2 echo "[rssg] ${index_file##$(pwd)/} $(echo "$rss" | grep -c '<item>') items"
55 echo "$rss"
56}
57
58
59usage() {
60 echo "usage: ${0##*/} index.{html,md} title > rss.xml" >&2
61 exit 1
62}
63
64
65no_file() {
66 echo "${0##*/}: $1: No such file" >&2
67 exit 2
68}
69
70
71md_to_html() {
72 test -x "$(which lowdown)" || exit 3
73 lowdown \
74 -D html-skiphtml \
75 -D smarty \
76 -d metadata \
77 -d autolink "$1"
78}
79
80
81get_title() {
82 awk -F '[<>]' '/<h1/ { gsub(/<h1>/, ""); gsub(/<\/h1>/, ""); sub(/ .*/, "", $3); print $0}' |
83 sed 's/^[ \t]*//;s/[ \t]*$//' |
84 awk 'FNR==1'
85}
86
87
88get_url() {
89 grep -i '<link .*rss.xml"' | head -1 |
90 sed 's#.*href="\(.*\)".*#\1#' |
91 sed 's#../../#https://gnunet.org/#'
92}
93
94
95get_items() {
96 grep -i 'href=".*" title="' |
97 sed 's#.*href="\(.*\)" title="\(.*\)">\(.*\)</a>.*#\1 \2 \3#'
98}
99
100
101get_description() {
102 start='sub("^.*<"s"*"t"("s"[^>]*)?>","")'
103 stop='sub("</"s"*"t""s"*>.*","")&&x=1'
104 awk -v 's=[[:space:]]' -v 't=[Pp]' "$start,$stop;x{exit}"
105}
106
107remove_tags() {
108 sed 's#<[^>]*>##g;s#</[^>]*>##g'
109}
110
111
112remove_nbsp() {
113 sed 's#\&nbsp;# #g'
114}
115
116
117rel_to_abs_urls() {
118 site_url="$1"
119 base_url="$2"
120
121 abs='s#(src|href)="/([^"]*)"#\1="'"$site_url"/'\2"#g'
122 rel='s#(src|href)="([^:/"]*)"#\1="'"$base_url"/'\2"#g'
123 sed -E "$abs;$rel"
124}
125
126
127date_rfc_822() {
128 if date --version >/dev/null 2>&1; then
129 in="$(echo "$1"| tr -cd '[:digit:]')0000"
130 year=$(echo $in | cut -c1-4)
131 month=$(echo $in | cut -c5-6)
132 day=$(echo $in | cut -c7-8)
133 hour=$(echo $in | cut -c9-10)
134 minute=$(echo $in | cut -c11-12)
135 date -d "$(echo "$year"-"$month"-"$day" "$hour":"$minute")" --rfc-822
136 else
137 date -j '+%a, %d %b %Y %H:%M:%S %z' \
138 "$(echo "$1"| tr -cd '[:digit:]')0000"
139 fi
140}
141
142
143feed_date_rfc_822() {
144 if date --version >/dev/null 2>&1; then
145 k="$($1)"
146 date -d "$(echo "$k")" --rfc-822
147 else
148 date -j '+%a, %d %b %Y %H:%M:%S %z' \
149 "$(echo "$1"| tr -cd '[:digit:]')0000"
150 fi
151}
152
153
154render_items() {
155 while read -r i
156 do render_item "$1" "$2" "$i"
157 done
158}
159
160
161render_item() {
162 base="$1"
163 base_url="$2"
164 item="$3"
165
166 site_url="$(echo "$base_url"| sed 's#\(.*//.*\)/.*#\1#')"
167
168 date=$(echo "$item"|awk '{print$2}')
169
170 url=$(echo "$item"|awk '{print$1}')
171
172 f="$base/$url"
173 test -f "$f" && html=$(cat "$f")
174 test -f "${f%\.html}.md" && html=$(md_to_html "${f%\.html}.md")
175
176 description=$(
177 echo "$html" |
178 rel_to_abs_urls "$site_url" "$base_url" |
179 remove_nbsp | awk '/<!--BEGIN-->/,/<!--END-->/'
180 )
181 title=$(echo "$description" | get_title)
182 guid="$base_url/$(echo "$url" | sed 's#^/##')"
183
184 echo '
185<item>
186<guid>'"$guid"'</guid>
187<link>'"$guid"'</link>
188<pubDate>'"$(date_rfc_822 "$date")"'</pubDate>
189<title>'"$title"'</title>
190<description><![CDATA[
191
192'"$description"'
193
194]]></description>
195</item>'
196}
197
198
199render_feed() {
200 url="$1"
201 title=$(echo "$2" | remove_nbsp)
202 description="$3"
203
204 base_url="$(echo "$url" | cut -d '/' -f1-3)"
205
206 echo '<?xml version="1.0" encoding="UTF-8"?>
207<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
208<channel>
209<atom:link href="'"$url"'" rel="self" type="application/rss+xml" />
210<title>'"$title"'</title>
211<language>en</language>
212<description>'"$description"'</description>
213<link>'"$base_url"'/</link>
214<lastBuildDate>'"$(feed_date_rfc_822 date)"'</lastBuildDate>
215'"$(cat)"'
216</channel></rss>'
217}
218
219
220main "$@"
diff --git a/www.yml b/www.yml
index ce0fa3ec..03f654ab 100644
--- a/www.yml
+++ b/www.yml
@@ -1,3 +1,12 @@
1siteconf:
2 - baseurl: gnunet.org
3 newsloc: /news/
4 newsdir: news
5 rsstitle: GNUnet.org
6 rssdescr: "News posts published by GNUnet about changes related to GNUnet, releases, and events"
7 rssloc:
8 rsslink:
9 rsslang:
1langs_full: &langs 10langs_full: &langs
2 en: English 11 en: English
3 fr: Français 12 fr: Français
@@ -50,83 +59,103 @@ newsposts:
50 - page: 2019-11-ICANNUpdate.html 59 - page: 2019-11-ICANNUpdate.html
51 date: 2019-11-10 60 date: 2019-11-10
52 title: GNS@ICANN66 61 title: GNS@ICANN66
53 abstract: 62 abstract:
63 content:
54 - page: 2019-0.11.8.html 64 - page: 2019-0.11.8.html
55 date: 2019-10-30 65 date: 2019-10-30
56 title: GNUnet 0.11.8 66 title: GNUnet 0.11.8
57 abstract: 67 abstract:
68 content:
58 - page: 2019-0.11.7.html 69 - page: 2019-0.11.7.html
59 date: 2019-10-27 70 date: 2019-10-27
60 title: GNUnet 0.11.7 71 title: GNUnet 0.11.7
61 abstract: 72 abstract:
73 content:
62 - page: 2019-10-ICANNPanel.html 74 - page: 2019-10-ICANNPanel.html
63 date: 2019-10-20 75 date: 2019-10-20
64 title: GNUnet invited to ICANN Panel 76 title: GNUnet invited to ICANN Panel
65 abstract: 77 abstract:
78 content:
66 - page: 2019-10-GNSSpec1.html 79 - page: 2019-10-GNSSpec1.html
67 date: 2019-10-04 80 date: 2019-10-04
68 title: GNS Specification Milestone 1/4 81 title: GNS Specification Milestone 1/4
69 abstract: 82 abstract:
83 content:
70 - page: 2019-0.11.6.html 84 - page: 2019-0.11.6.html
71 date: 2019-07-24 85 date: 2019-07-24
72 title: GNUnet 0.11.6 86 title: GNUnet 0.11.6
73 abstract: 87 abstract:
88 content:
74 - page: 2019-07-GHM_Aug_2019.html 89 - page: 2019-07-GHM_Aug_2019.html
75 date: 2019-07-17 90 date: 2019-07-17
76 title: GNUnet Hacker Meeting 2019 91 title: GNUnet Hacker Meeting 2019
77 abstract: 92 abstract:
93 content:
78 - page: 2019-06-DSTJ.html 94 - page: 2019-06-DSTJ.html
79 date: 2019-06-28 95 date: 2019-06-28
80 title: "Peer DSTJ is dead, long live peer Y924" 96 title: "Peer DSTJ is dead, long live peer Y924"
81 abstract: 97 abstract:
98 content:
82 - page: 2019-0.11.5.html 99 - page: 2019-0.11.5.html
83 date: 2019-06-05 100 date: 2019-06-05
84 title: GNUnet 0.11.5 101 title: GNUnet 0.11.5
85 abstract: 102 abstract:
103 content:
86 - page: 2019-06.html 104 - page: 2019-06.html
87 date: 2019-06-01 105 date: 2019-06-01
88 title: 2019-06 106 title: 2019-06
89 abstract: 107 abstract:
108 content:
90 - page: 2019-0.11.4.html 109 - page: 2019-0.11.4.html
91 date: 2019-05-12 110 date: 2019-05-12
92 title: GNUnet 0.11.4 111 title: GNUnet 0.11.4
93 abstract: 112 abstract:
113 content:
94 - page: 2019-0.11.3.html 114 - page: 2019-0.11.3.html
95 date: 2019-04-07 115 date: 2019-04-07
96 title: GNUnet 0.11.3 116 title: GNUnet 0.11.3
97 abstract: 117 abstract:
118 content:
98 - page: 2019-0.11.2.html 119 - page: 2019-0.11.2.html
99 date: 2019-04-04 120 date: 2019-04-04
100 title: GNUnet 0.11.2 121 title: GNUnet 0.11.2
101 abstract: 122 abstract:
123 content:
102 - page: 2019-0.11.1.html 124 - page: 2019-0.11.1.html
103 date: 2019-04-03 125 date: 2019-04-03
104 title: GNUnet 0.11.1 126 title: GNUnet 0.11.1
105 abstract: 127 abstract:
128 content:
106 - page: 2019-0.11.0.html 129 - page: 2019-0.11.0.html
107 date: 2019-02-28 130 date: 2019-02-28
108 title: GNUnet 0.11.0 131 title: GNUnet 0.11.0
109 abstract: 132 abstract:
133 content:
110 - page: 2019-02.html 134 - page: 2019-02.html
111 date: 2019-02-01 135 date: 2019-02-01
112 title: Google Summer of Code 2019 136 title: Google Summer of Code 2019
113 abstract: 137 abstract:
138 content:
114 - page: 2018-08.html 139 - page: 2018-08.html
115 date: 2018-08-14 140 date: 2018-08-14
116 title: GSoC 2018 - GNUnet Web-based User Interface 141 title: GSoC 2018 - GNUnet Web-based User Interface
117 abstract: 142 abstract:
143 content:
118 - page: 2018-07.html 144 - page: 2018-07.html
119 date: 2018-07-01 145 date: 2018-07-01
120 title: Second GNUnet Hacker Meeting 2018 146 title: Second GNUnet Hacker Meeting 2018
121 abstract: 147 abstract:
148 content:
122 - page: 2018-06.html 149 - page: 2018-06.html
123 date: 2018-06-06 150 date: 2018-06-06
124 title: GNUnet 0.11.0pre66 151 title: GNUnet 0.11.0pre66
125 abstract: 152 abstract:
153 content:
126 - page: 2017-10.html 154 - page: 2017-10.html
127 date: 2017-10-01 155 date: 2017-10-01
128 title: Launching the new gnunet.org 156 title: Launching the new gnunet.org
129 abstract: 157 abstract:
158 content:
130# <!-- FIXME 2015: source only available on yt. <li>Ludovic Courtès, <a href="">Reproducible Software Deployment with GNU Guix</a>, Inria</li> --> 159# <!-- FIXME 2015: source only available on yt. <li>Ludovic Courtès, <a href="">Reproducible Software Deployment with GNU Guix</a>, Inria</li> -->
131# <!-- FIXME 2014: no source link on web. <li>Julian Kirsch, <a href="">"Knocking down the HACIENDA"</a>, GNU Hacker Meeting 2014</li> --> 160# <!-- FIXME 2014: no source link on web. <li>Julian Kirsch, <a href="">"Knocking down the HACIENDA"</a>, GNU Hacker Meeting 2014</li> -->
132# <!-- FIXME 2014: no source link on web. <li>Peter Schaar, <a href="">"Technik, Recht und Überwachung"</a>, Technische Universität München</li> --> 161# <!-- FIXME 2014: no source link on web. <li>Peter Schaar, <a href="">"Technik, Recht und Überwachung"</a>, Technische Universität München</li> -->