summaryrefslogtreecommitdiffstats
path: root/web/macros.py
diff options
context:
space:
mode:
Diffstat (limited to 'web/macros.py')
-rw-r--r--web/macros.py107
1 files changed, 90 insertions, 17 deletions
diff --git a/web/macros.py b/web/macros.py
index f3b6ec6..5918195 100644
--- a/web/macros.py
+++ b/web/macros.py
@@ -8,9 +8,13 @@ page = {
8 "description": "Standard monitoring plugins for Nagios and compatible monitoring solutions.", 8 "description": "Standard monitoring plugins for Nagios and compatible monitoring solutions.",
9 "keywords": "Nagios, Icinga, Shinken, Monitoring, Official, Plugins, Open, Source, Free, Software" 9 "keywords": "Nagios, Icinga, Shinken, Monitoring, Official, Plugins, Open, Source, Free, Software"
10} 10}
11release_notes = 'doc/release-notes/' + plugins_release.replace('.', '-') + '.html' 11release_notes = 'news/release-%s.html' % plugins_release.replace('.', '-')
12site_url = 'https://www.nagios-plugins.org/' 12site_url = 'https://www.nagios-plugins.org/'
13 13
14#
15# RSS Feed
16#
17
14_RSS = """<?xml version="1.0" encoding="UTF-8"?> 18_RSS = """<?xml version="1.0" encoding="UTF-8"?>
15<rss version="2.0"> 19<rss version="2.0">
16 <channel> 20 <channel>
@@ -40,15 +44,14 @@ _RSS_ITEM = """
40 44
41def hook_postconvert_rss(): 45def hook_postconvert_rss():
42 items = [] 46 items = []
43 posts = [p for p in pages if 'post' in p] 47 posts = [p for p in pages if 'date' in p]
44 posts.sort(key=lambda p: p.date, reverse=True) 48 posts.sort(key=lambda p: p.date, reverse=True)
45 for p in posts: 49 for p in posts:
46 title = p.post
47 link = '%s/%s' % (site_url.rstrip('/'), p.url) 50 link = '%s/%s' % (site_url.rstrip('/'), p.url)
48 desc = hx(p.html) 51 desc = hx(p.html)
49 date = time.mktime(time.strptime('%s 12' % p.date, '%Y-%m-%d %H')) 52 date = time.mktime(time.strptime('%s 12' % p.date, '%Y-%m-%d %H'))
50 date = email.utils.formatdate(date) 53 date = email.utils.formatdate(date)
51 items.append(_RSS_ITEM % (title, link, desc, link, date)) 54 items.append(_RSS_ITEM % (p.title, link, desc, date, link))
52 items = ''.join(items) 55 items = ''.join(items)
53 title = 'Nagios Plugins' 56 title = 'Nagios Plugins'
54 link = '%s/news/index.html' % site_url.rstrip('/') 57 link = '%s/news/index.html' % site_url.rstrip('/')
@@ -59,23 +62,84 @@ def hook_postconvert_rss():
59 fp.write(rss) 62 fp.write(rss)
60 fp.close() 63 fp.close()
61 64
62def list_posts(max_posts=-1): 65#
63 posts = [p for p in pages if 'post' in p] 66# News
67#
68
69def hook_preconvert_news():
70 posts_per_page = 10
71 posts = [p for p in pages if 'date' in p]
64 posts.sort(key=lambda p: p.date, reverse=True) 72 posts.sort(key=lambda p: p.date, reverse=True)
65 if max_posts == -1: 73 n_news_pages = len(posts) / posts_per_page
66 max_posts = len(posts) 74 if len(posts) % posts_per_page > 0:
67 for p in posts[:max_posts]: 75 n_news_pages += 1
68 date = time.strftime('%B %d, %Y', time.strptime(p['date'], '%Y-%m-%d')) 76 for i, chunk in enumerate(next_news_chunk(posts, posts_per_page)):
69 print '* **[%s](%s)** (%s)' % (p.post, p.url, date) 77 content = make_news_page(chunk, i) + make_news_footer(n_news_pages, i)
78 if i == 0:
79 p = Page('news/index.md',
80 virtual=content,
81 menu=2,
82 title='News',
83 parent='Home')
84 else:
85 p = Page('news/%d.md' % (i + 1),
86 virtual=content,
87 title='News Page %d' % (i + 1),
88 parent='News')
89 pages.append(p)
70 90
71def list_kids(): 91def make_news_page(posts, current_index):
72 kids = [(p.url, p.title) for p in pages if p.get('parent') == page.title] 92 marker = '<end-of-abstract>'
73 for kid in sorted(kids): 93 source = list()
74 print('* [%s](%s)' % (kid[1], kid[0])) 94 if current_index == 0:
95 title = 'News'
96 else:
97 title = 'News Page %d' % (current_index + 1)
98 abstract = ['# ' + title]
99 for p in posts:
100 timestamp = time.strptime(p.date, '%Y-%m-%d')
101 date = time.strftime('%A, %B %-e, %Y', timestamp)
102 abstract.append('## %s' % p.title)
103 abstract.append('*%s*' % date)
104 abstract.append('%s' % p.source.split(marker, 1)[0])
105 abstract.append('[<a href="%s">Read more</a>]' % p.url)
106 source.append('# %s' % p.title)
107 source.append('*%s*' % date)
108 source.append(p.source.replace(marker, '', 1))
109 p.source = '\n'.join(source)
110 p['parent'] = title
111 return '\n'.join(abstract) + '\n\n'
112
113def make_news_footer(n_news_pages, current_index):
114 footer = list()
115 if current_index != 0:
116 previous = 'index' if current_index == 1 else str(current_index)
117 footer.append('[First](news/index.html)')
118 footer.append('[Previous](news/%s.html)' % previous)
119 if n_news_pages <= 20:
120 for i in range(n_news_pages):
121 if i == current_index:
122 footer.append('%d' % (i + 1))
123 else:
124 footer.append('[%d](news/%d.html)' % (i + 1, i + 1))
125 if current_index != n_news_pages - 1:
126 footer.append('[Next](news/%d.html)' % (current_index + 2))
127 footer.append('[Last](news/%d.html)' % n_news_pages)
128 return '&emsp;'.join(footer) + '\n{: #news-footer }\n'
129
130def next_news_chunk(posts, posts_per_page):
131 index = 0
132 while len(posts[index:]) > 0:
133 yield posts[index:index + posts_per_page]
134 index += posts_per_page
135
136#
137# Menu and Breadcrumb Navigation
138#
75 139
76def menu(): 140def menu():
77 menu_pages = [p for p in pages if 'menu-position' in p] 141 menu_pages = [p for p in pages if 'menu' in p]
78 menu_pages.sort(key=lambda p: int(p['menu-position'])) 142 menu_pages.sort(key=lambda p: int(p['menu']))
79 for p in menu_pages: 143 for p in menu_pages:
80 if p.title == page.title: 144 if p.title == page.title:
81 print('<span id="current">%s</span>' % hx(p.title)) 145 print('<span id="current">%s</span>' % hx(p.title))
@@ -96,6 +160,15 @@ def breadcrumb():
96 crumbs = '&nbsp;' + stable 160 crumbs = '&nbsp;' + stable
97 return crumbs 161 return crumbs
98 162
163#
164# Miscellaneous
165#
166
167def list_kids():
168 kids = [(p.url, p.title) for p in pages if p.get('parent') == page.title]
169 for kid in sorted(kids):
170 print('* [%s](%s)' % (kid[1], kid[0]))
171
99def copyright_years(since=None): 172def copyright_years(since=None):
100 this_year = time.gmtime().tm_year 173 this_year = time.gmtime().tm_year
101 if since is not None and int(since) != this_year: 174 if since is not None and int(since) != this_year: