page-relations.py - Parent-Child-Relations (2/2)

Parent-Child-Relations by Directory Structure (2/2)

As special rule all toplevel pages with children get the landing page as parent. That is used for defining the menu.

    # make toplevel index page to parent of toplevel pages with children
    for page in _all_pages():
        page_dir = get_path(page, page.settings)
        if page_dir == '/' and page.slug == 'index':
            for child_page in _all_pages():
                if child_page != page and child_page.lang == page.lang:
                    childpage_dir = get_path(child_page, child_page.settings)
                    if childpage_dir == '/' and len(child_page.children) > 0:
                        child_page.parent = page
                        page.children.append(child_page)

Finally, the complete line of ancestors is computed for all pages. This serves the construction of bread crumbs.

    # set parents from parent
    for page in _all_pages():
        super_parent = page.parent
        while super_parent:
            page.parents.insert(0, super_parent)
            super_parent = super_parent.parent

Copyright © 2016 Uwe Ritzmann - Created with Pelican, Python and Skeleton.