ListTopicSubpages

Table of contents
No headers
/***
    USAGE:

    ListTopicSubpages(topic_page, pages, categories, hierarchy, subpages)
        Generates a list of subpages for a given topic page

    PARAMETERS:

    topic_page : page
        Root topic page for which to display sublist 

    pages : list
        List of all topic pages the guide covers. Expected to be tagged with tutorial, reference, troubleshooting or topic.

    (optional) categories : list of maps
        Array of items such as [{category: 'tutorial'}, {category:'reference'}] containing the fields to search for and display.

    hierarchy : map (optional)
        Map listing all child pages by parent id.
        
    subpages : list (optional)
        List of subpages of current page.
***/

var topic_page = $topic_page ?? $0;
var pages = $pages ?? $1;
var categories = $categories ?? $2 ?? [
    { category: 'topic' },
    { category: 'tutorial' },
    { category: 'reference' },
    { category: 'troubleshooting' }
];
var hierarchy = $4 ?? $hierarchy;
var subpages = $5 ?? $subpages;

if(subpages is nil) {
    let subpages = hierarchy ? hierarchy[topic_page.id] : [ p foreach var p in pages where p.parent_id == topic_page.id ];
    if(#subpages === 0) {
        return;
    }
}

var pages_in_category = { };
var has_subpages = false;
foreach(var c in categories) {
    let pages_in_category = pages_in_category .. {
        (c.category): [ p foreach var p in subpages where p[c.category] ]
    };
    if(#pages_in_category[c.category]) {
        let has_subpages = true;
    }
}
if(!has_subpages) {
    return;
}
<div class="noindex">
    <div class="mt-idf-subtopic-container">
        foreach (var c in categories) {
            if(#pages_in_category[c.category]) {
                <ul id=('mt-idf-topic-' .. topic_page.id .. '-' .. c.category .. '-details')
                    class=('mt-idf-topic-' .. topic_page.id .. '-details')
                >
                    foreach (var p in pages_in_category[c.category]) {
                        <li>
                            web.link(p.uri, p.title);
                            <span class="mt-idf-category">'(' .. wiki.localize('MindTouch.IDF.guide.category.' .. c.category) .. ')'</span>
                        </li>
                    }
                </ul>
            }
        }
    </div>
</div>
Page statistics
43 view(s), 3 edit(s) and 2421 character(s)

Tags

This page has no custom tags set.

Comments

You must to post a comment.

Attach file

Attachments