Home » Projekte » Webber » Plugins » hierarchy.py

Generate hierarchy

This is one of the more complex plugins, used to generate menus and breadcrumbs. For this, it reads certain keyword from the Page format, built an internal parent-child representation.

This is later used for by the functions "get_breadcrumbs()" and "get_sidemenu()", which you call from the Mako templates.

Page attributes 

At the "scan" hook, the plugin looks for entries like:

parent: Home

or

childs: Cmdline, Inheritance

Here's an example of five pages with different attributes:


title: Homepage
linktitle: Home

title: Impressum
parent: Home

title: Job
parent: Home

title: CV
parent: Job

title: Knowledge
parent: Job

Internal representation 

the plugin would populate the variables "_childs" and "_parent" like this:

_parent = {
    'Impressum': 'Home',
    'CV': 'Job',
    'Knowledge': 'Job',
    'Job': 'Home'
}

_childs = {
    'Home': [(100, 'Job'),
             (100, 'Impressum')],
    'Job':  [(100, 'CV'),
             (100, 'Knowledge')]}

That's all you need to generate a sidemap, breadcrumbs or a side-menu.

The pages are first ordered by some number, then by the "linktitle". If a page has no "linktitle:" attribute, then the normal title will be used instead.

If you want to modify the sort-order, simply specify a "order: 200" in the page itself.

Generation of breadcrumbs 

This is done via a suitable Mako templates. The template uses the function "get_breadcrumbs()" and returns (linktitle, link) tuples. As a bonus: all the links are always relative to the calling page.

Here's a sample Mako template excerpt:

\

Generation of a side-menu 

This again is done via a suitable Mako templates. The template uses the function "get_sidemenu()" which returns (level, part_of_path, is_current, title, link) tuples. Again all links are relative to the calling page.

Here's a sample Mako template excerpt that converts this into a HTML menu:


Generate a list of recently changed pages 

To get a list of recently changed pages, do this:

<%
  history = get_recently())
%>
% if len(history)>1:

Recent changed

% for page, link in history: % if page.mtime > page.ctime: Modified ${format_date(page.mtime)}\ % else: Created ${format_date(page.ctime)}\ % endif : ${page.title | entity}
% endfor % endif

Generate a sitemap 

To generate a site map for your whole project, do something like this:

<%
  site = get_linear_sitemap()
%>

Now you'd need to use CSS to indent the entries. If you prefer a more normal "

<% lvl -= 1 %> % endwhile