doctype xml

- var DOCS_ROOT = `https://docs.mobify.com${PROD_ROOT}`
- var COMPONENTS_LIST_SLUG = '_componentsList'

mixin renderComponentLink(slug, path)
    url
        loc #{path}/#!/#{slug}

mixin renderMenuLink(slug, path, data)
    url
        loc #{path}/#{slug}/
        if (data.crawlPriority)
            priority #{data.crawlPriority}

mixin renderMenu(level, path, node)
    each item, slug in node._data
        //- Ignore special slugs
        //- The COMPONENTS_LIST_SLUG has to start with '_' so that it is skipped in the sidebar,
        //- however, it's prime purpose is for use in the sitemap, so we better not skip it here.
        if ((slug.startsWith('_') && slug !== COMPONENTS_LIST_SLUG) || slug === "styleguidist" || slug === "index")
            - continue;

        - var hasChildren = node[slug] && node[slug]._data
        if (slug === COMPONENTS_LIST_SLUG)
            each componentSlug in public.latest.components._data[COMPONENTS_LIST_SLUG]
                +renderComponentLink(componentSlug, path)
        else
            +renderMenuLink(slug, path, node._data[slug])

        if (level === 1 && hasChildren)
            +renderMenu(level + 1, path + '/' + slug, node[slug])

urlset(xmlns='http://www.sitemaps.org/schemas/sitemap/0.9')
    if public['latest'] && public['latest']._data
        +renderMenu(1, DOCS_ROOT + 'latest', public['latest'])
