summaryrefslogtreecommitdiffstats
path: root/web/macros.py
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2013-10-07 08:06:32 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2013-10-07 08:06:32 (GMT)
commit3b7e8e8504437fc3299661359b270e67f6bc387c (patch)
tree8ba2c69450c6127200d7c730648bf93edb152afa /web/macros.py
parent76af1279d9a4ab574d87e93466166b7b210c2bad (diff)
downloadsite-3b7e8e8504437fc3299661359b270e67f6bc387c.tar.gz
Add support for news articles and RSS feed
Add infrastructure for creating lists of news articles and for distributing them via RSS 2.0.
Diffstat (limited to 'web/macros.py')
-rw-r--r--web/macros.py69
1 files changed, 64 insertions, 5 deletions
diff --git a/web/macros.py b/web/macros.py
index 6ee8393..eaaf7d9 100644
--- a/web/macros.py
+++ b/web/macros.py
@@ -1,3 +1,5 @@
1import email.utils
2import os.path
1import time 3import time
2 4
3plugins_release = '1.5' 5plugins_release = '1.5'
@@ -8,6 +10,68 @@ page = {
8} 10}
9release_notes = 'doc/release-notes/' + plugins_release.replace('.', '-') + '.html' 11release_notes = 'doc/release-notes/' + plugins_release.replace('.', '-') + '.html'
10 12
13_RSS = """<?xml version="1.0" encoding="UTF-8"?>
14<rss version="2.0">
15 <channel>
16 <title>%s</title>
17 <link>%s</link>
18 <description>%s</description>
19 <language>en-us</language>
20 <webMaster>webmaster@nagios-plugins.org</webMaster>
21 <pubDate>%s</pubDate>
22 <lastBuildDate>%s</lastBuildDate>
23 <generator>Poole</generator>
24 <docs>http://blogs.law.harvard.edu/tech/rss</docs>
25 %s
26 </channel>
27</rss>
28"""
29
30_RSS_ITEM = """
31 <item>
32 <title>%s</title>
33 <link>%s</link>
34 <description>%s</description>
35 <guid>%s</guid>
36 <pubDate>%s</pubDate>
37 </item>
38"""
39
40def hook_postconvert_rss():
41 items = []
42 posts = [p for p in pages if 'post' in p]
43 posts.sort(key=lambda p: p.date, reverse=True)
44 for p in posts:
45 title = p.post
46 link = '%s/%s' % (options.base_url.rstrip('/'), p.url)
47 desc = hx(p.html)
48 date = time.mktime(time.strptime('%s 12' % p.date, '%Y-%m-%d %H'))
49 date = email.utils.formatdate(date)
50 items.append(_RSS_ITEM % (title, link, desc, date, link))
51 items = ''.join(items)
52 title = 'Nagios Plugins'
53 link = '%s/news/index.html' % options.base_url.rstrip('/')
54 desc = 'Announcements published by the Nagios Plugins Development Team.'
55 date = email.utils.formatdate()
56 rss = _RSS % (title, link, desc, date, date, items)
57 fp = open(os.path.join(output, 'rss.xml'), 'w')
58 fp.write(rss)
59 fp.close()
60
61def list_posts(max_posts=-1):
62 posts = [p for p in pages if 'post' in p]
63 posts.sort(key=lambda p: p.date, reverse=True)
64 if max_posts == -1:
65 max_posts = len(posts)
66 for p in posts[:max_posts]:
67 date = time.strftime('%B %d, %Y', time.strptime(p['date'], '%Y-%m-%d'))
68 print '* **[%s](%s)** (%s)' % (p.post, p.url, date)
69
70def list_kids():
71 kids = [(p.url, p.title) for p in pages if p.get('parent') == page.title]
72 for kid in sorted(kids):
73 print('* [%s](%s)' % (kid[1], kid[0]))
74
11def menu(): 75def menu():
12 menu_pages = [p for p in pages if 'menu-position' in p] 76 menu_pages = [p for p in pages if 'menu-position' in p]
13 menu_pages.sort(key=lambda p: int(p['menu-position'])) 77 menu_pages.sort(key=lambda p: int(p['menu-position']))
@@ -31,11 +95,6 @@ def breadcrumb():
31 crumbs = '&nbsp;' + stable 95 crumbs = '&nbsp;' + stable
32 return crumbs 96 return crumbs
33 97
34def list_kids():
35 kids = [(p.url, p.title) for p in pages if p.get('parent') == page.title]
36 for kid in sorted(kids):
37 print('* [%s](%s)' % (kid[1], kid[0]))
38
39def copyright_years(since=None): 98def copyright_years(since=None):
40 this_year = time.gmtime().tm_year 99 this_year = time.gmtime().tm_year
41 if since is not None and int(since) != this_year: 100 if since is not None and int(since) != this_year: