<%
var titlesBySection = {
        // top-level
        astral: "Astral Info",
        campaigns: "Campaigns",
        campaign: "Astral Campaign Info",
        classes: "Character Classes",
        "magic-items": "Magic Items",
        planes: "the Cosmology of the Multiverse",
        races: "Character Races",
        rules: "Core Rules",

        // campaigns
        "aeryon": "the World of Aeryon",
        "one-night": "One Night One-Shots",
        "mini-campaigns": "Monday Night Mini-Campaigns",

        // creatures
        "dragons-chromatic": "Chromatic Dragons",
        "dragons-crystalline": "Crystalline Dragons",
        "dragons-metallic": "Metallic Dragons",
        "herd-mammals": "Herd Mammals",

        // planes
        elemental: "Elemental Planes",
        material: "Material Planes",
        near: "the Near Planes",
        transcendental: "Transcendental Planes",
        "near-faewolde": "The Faewolde",

        equipment: "Equipment Tables",
    },
    unlistedSections = ['main'],
    nestedSubsections = ['near'],
    fixedSection = page?.section?.replace(/\s+/, '-');
%>

<% if (page.path && page.section && page.section === 'licenses' &&
    !page.path.endsWith(`${page.section}/index.html`)) { -%>

    <p>
        The latest version of this license can always be found at
        <a href="/<%=page.path%>"><%=site.uri%>/<%=page.path.replace('/index.html', '/')%></a>.
    </p>

<% } else if (page.path && page.subsection && page.subsection.includes('dragons') &&
    page.path.endsWith(`${page.subsection.replace('-', '/')}/index.html`)) { %>

        <div class="sectionBackLink-wrapper">
            <a href="../" class="sectionBackLink">
                &lt; Back to Dragons
            </a>
        </div>

<% } else if (page.path && page.subsection && nestedSubsections.includes(page.subsection)) { %>

        <div class="sectionBackLink-wrapper">
            <a href="../" class="sectionBackLink">
                &lt; Back to <%= titlesBySection[page.subsection] %>
            </a>
        </div>
    
<% } else if (page.path && page.subsection &&
    !page.path.endsWith(`${page.subsection.replace('-', '/')}/index.html`)) { %>

    <div class="sectionBackLink-wrapper">
        <a href="./" class="sectionBackLink">
            &lt; Back to <%= titlesBySection[page.subsection]
                ?? page.subsection.charAt(0).toUpperCase() + page.subsection.slice(1) %>
        </a>
    </div>

<% } else if (fixedSection && !unlistedSections.includes(fixedSection) && page.path &&
    !(page.path === `${fixedSection}/index.html` || page.path.endsWith(`/${fixedSection}/index.html`))) { -%>

    <div class="sectionBackLink-wrapper">
        <a href="/<%=fixedSection%>/" class="sectionBackLink">
            &lt; Back to <%= titlesBySection[fixedSection] ?? page.section.charAt(0).toUpperCase() + page.section.slice(1) %>
        </a>
    </div>

<% } -%>

