diff options
Diffstat (limited to 'web/macros.py')
-rw-r--r-- | web/macros.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/web/macros.py b/web/macros.py new file mode 100644 index 0000000..a4566fe --- /dev/null +++ b/web/macros.py | |||
@@ -0,0 +1,43 @@ | |||
1 | import time | ||
2 | |||
3 | plugins_release = '1.4.16' | ||
4 | mib_release = '1.0.1' | ||
5 | page = { | ||
6 | "description": "Standard plugins for Nagios and compatible monitoring solutions.", | ||
7 | "keywords": "Nagios, Icinga, Shinken, Monitoring, Official, Plugins, Open, Source, Free, Software" | ||
8 | } | ||
9 | |||
10 | def menu(): | ||
11 | menu_pages = [p for p in pages if 'menu-position' in p] | ||
12 | menu_pages.sort(key=lambda p: int(p['menu-position'])) | ||
13 | for p in menu_pages: | ||
14 | if p.title == page.title: | ||
15 | print('<span class="current">%s</span>' % hx(p.title)) | ||
16 | else: | ||
17 | print('<span><a href="%s">%s</a></span>' % (p.url, hx(p.title))) | ||
18 | |||
19 | def breadcrumb(): | ||
20 | parents = {p.title: (p.url, p.get('parent')) for p in pages} | ||
21 | title = page.title | ||
22 | output = hx(title) | ||
23 | while parents[title][1] is not None: | ||
24 | title = parents[title][1] | ||
25 | url = parents[title][0] | ||
26 | output = '<a href="%s">%s</a> > %s' % (url, hx(title), output) | ||
27 | if output == hx(page.title): # Hide breadcrumb if the page has no parent. | ||
28 | output = ' ' | ||
29 | return output | ||
30 | |||
31 | def list_kids(): | ||
32 | kids = [(p.url, p.title) for p in pages if p.get('parent') == page.title] | ||
33 | for kid in sorted(kids): | ||
34 | print('* [%s](%s)' % (kid[1], kid[0])) | ||
35 | |||
36 | def copyright_years(since=None): | ||
37 | this_year = time.gmtime().tm_year | ||
38 | if since is not None and int(since) != this_year: | ||
39 | return str(since) + '–' + str(this_year) | ||
40 | else: | ||
41 | return str(this_year) | ||
42 | |||
43 | # vim:set expandtab softtabstop=4 shiftwidth=4 textwidth=80: | ||