From 3b7e8e8504437fc3299661359b270e67f6bc387c Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Mon, 7 Oct 2013 10:06:32 +0200 Subject: Add support for news articles and RSS feed Add infrastructure for creating lists of news articles and for distributing them via RSS 2.0. 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 @@ +import email.utils +import os.path import time plugins_release = '1.5' @@ -8,6 +10,68 @@ page = { } release_notes = 'doc/release-notes/' + plugins_release.replace('.', '-') + '.html' +_RSS = """ + + + %s + %s + %s + en-us + webmaster@nagios-plugins.org + %s + %s + Poole + http://blogs.law.harvard.edu/tech/rss + %s + + +""" + +_RSS_ITEM = """ + + %s + %s + %s + %s + %s + +""" + +def hook_postconvert_rss(): + items = [] + posts = [p for p in pages if 'post' in p] + posts.sort(key=lambda p: p.date, reverse=True) + for p in posts: + title = p.post + link = '%s/%s' % (options.base_url.rstrip('/'), p.url) + desc = hx(p.html) + date = time.mktime(time.strptime('%s 12' % p.date, '%Y-%m-%d %H')) + date = email.utils.formatdate(date) + items.append(_RSS_ITEM % (title, link, desc, date, link)) + items = ''.join(items) + title = 'Nagios Plugins' + link = '%s/news/index.html' % options.base_url.rstrip('/') + desc = 'Announcements published by the Nagios Plugins Development Team.' + date = email.utils.formatdate() + rss = _RSS % (title, link, desc, date, date, items) + fp = open(os.path.join(output, 'rss.xml'), 'w') + fp.write(rss) + fp.close() + +def list_posts(max_posts=-1): + posts = [p for p in pages if 'post' in p] + posts.sort(key=lambda p: p.date, reverse=True) + if max_posts == -1: + max_posts = len(posts) + for p in posts[:max_posts]: + date = time.strftime('%B %d, %Y', time.strptime(p['date'], '%Y-%m-%d')) + print '* **[%s](%s)** (%s)' % (p.post, p.url, date) + +def list_kids(): + kids = [(p.url, p.title) for p in pages if p.get('parent') == page.title] + for kid in sorted(kids): + print('* [%s](%s)' % (kid[1], kid[0])) + def menu(): menu_pages = [p for p in pages if 'menu-position' in p] menu_pages.sort(key=lambda p: int(p['menu-position'])) @@ -31,11 +95,6 @@ def breadcrumb(): crumbs = ' ' + stable return crumbs -def list_kids(): - kids = [(p.url, p.title) for p in pages if p.get('parent') == page.title] - for kid in sorted(kids): - print('* [%s](%s)' % (kid[1], kid[0])) - def copyright_years(since=None): this_year = time.gmtime().tm_year if since is not None and int(since) != this_year: -- cgit v0.10-9-g596f