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

Parent-Child-Relations by Driectory Structure (1/2)

As directory names have to match with the slug of a parent the analysis can work on the file paths.

At first we stick to same-language relations:

    # set parent and children
    for page in _all_pages():
        page_dir = get_path(page, page.settings)
        for parent_page in _all_pages():
            parentpage_dir = get_path(parent_page, parent_page.settings)
            parentpage_as_dir = parentpage_dir + parent_page.slug + '/'
            if parentpage_as_dir == page_dir and parent_page != page and parent_page.lang == page.lang:
                page.parent = parent_page
                parent_page.children.append(page)

Then we check whether parent-less pages can get a "step-parent" in the default language:

    # set parent in default language if necessary
    for page in _all_pages():
        if not page.parent:
            page_dir = get_path(page, page.settings)
            for parent_page in _all_pages():
                parentpage_dir = get_path(parent_page, parent_page.settings)
                parentpage_as_dir = parentpage_dir + parent_page.slug + '/'
                if parentpage_as_dir == page_dir and parent_page != page and parent_page.in_default_lang:
                    page.parent = parent_page

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