summaryrefslogtreecommitdiffstats
path: root/web/macros.py
blob: a4566fe44c380adad4552d35fd03f7f8ba82432c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import time

plugins_release = '1.4.16'
mib_release = '1.0.1'
page = {
    "description": "Standard plugins for Nagios and compatible monitoring solutions.",
    "keywords": "Nagios, Icinga, Shinken, Monitoring, Official, Plugins, Open, Source, Free, Software"
}

def menu():
    menu_pages = [p for p in pages if 'menu-position' in p]
    menu_pages.sort(key=lambda p: int(p['menu-position']))
    for p in menu_pages:
        if p.title == page.title:
            print('<span class="current">%s</span>' % hx(p.title))
        else:
            print('<span><a href="%s">%s</a></span>' % (p.url, hx(p.title)))

def breadcrumb():
    parents = {p.title: (p.url, p.get('parent')) for p in pages}
    title = page.title
    output = hx(title)
    while parents[title][1] is not None:
        title = parents[title][1]
        url = parents[title][0]
        output = '<a href="%s">%s</a> &gt; %s' % (url, hx(title), output)
    if output == hx(page.title): # Hide breadcrumb if the page has no parent.
        output = '&nbsp;'
    return output

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:
        return str(since) + '&ndash;' + str(this_year)
    else:
        return str(this_year)

# vim:set expandtab softtabstop=4 shiftwidth=4 textwidth=80: