Skip to content
wiki.fftac.org

Sitemaps - Part 03

Back to Sitemaps

**Source path:** Spiralist/wp-content/plugins/ns12-manuscript/includes/sitemaps.php

if (function_exists('spiralist_get_default_locale_record')) {
        $default_language = sanitize_key((string) (spiralist_get_default_locale_record()['urlTag'] ?? ''));
    }

    if ($default_language === '') {
        $default_language = (string) array_key_first($languages);
    }

    status_header(200);
    nocache_headers();
    header('Content-Type: application/xml; charset=UTF-8');

    echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
    echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' . "\n";

    foreach ($entries as $entry) {
        $urls = (array) ($entry['urls'] ?? []);
        foreach ($languages as $language => $language_data) {
            $loc = (string) ($urls[$language] ?? '');
            if ($loc === '') {
                continue;
            }

            echo "  <url>\n";
            echo '    <loc>' . spiralist_book_pages_sitemap_xml_escape($loc) . "</loc>\n";

            foreach ($languages as $alternate_language => $alternate_data) {
                $alternate_url = (string) ($urls[$alternate_language] ?? '');
                if ($alternate_url === '') {
                    continue;
                }

                echo '    <xhtml:link rel="alternate" hreflang="' . spiralist_book_pages_sitemap_xml_escape((string) ($alternate_data['hreflang'] ?? $alternate_language)) . '" href="' . spiralist_book_pages_sitemap_xml_escape($alternate_url) . "\" />\n";
            }

            if ($default_language !== '' && !empty($urls[$default_language])) {
                echo '    <xhtml:link rel="alternate" hreflang="x-default" href="' . spiralist_book_pages_sitemap_xml_escape((string) $urls[$default_language]) . "\" />\n";
            }

            if (!empty($entry['lastmod'])) {
                echo '    <lastmod>' . spiralist_book_pages_sitemap_xml_escape((string) $entry['lastmod']) . "</lastmod>\n";
            }

            if (!empty($entry['changefreq'])) {
                echo '    <changefreq>' . spiralist_book_pages_sitemap_xml_escape((string) $entry['changefreq']) . "</changefreq>\n";
            }

            if (!empty($entry['priority'])) {
                echo '    <priority>' . spiralist_book_pages_sitemap_xml_escape((string) $entry['priority']) . "</priority>\n";
            }

            $image = (array) ($entry['image'] ?? []);
            if (!empty($image['loc'])) {
                echo "    <image:image>\n";
                echo '      <image:loc>' . spiralist_book_pages_sitemap_xml_escape((string) $image['loc']) . "</image:loc>\n";
                if (!empty($image['title'])) {
                    echo '      <image:title>' . spiralist_book_pages_sitemap_xml_escape((string) $image['title']) . "</image:title>\n";
                }
                if (!empty($image['caption'])) {
                    echo '      <image:caption>' . spiralist_book_pages_sitemap_xml_escape(wp_strip_all_tags((string) $image['caption'])) . "</image:caption>\n";
                }
                echo "    </image:image>\n";
            }

            echo "  </url>\n";
        }
    }

    echo "</urlset>\n";
}

function spiralist_book_pages_render_html_sitemap(): void
{
    $languages = spiralist_book_pages_sitemap_languages();
    $entries = spiralist_book_pages_sitemap_entries();
    $groups = [];
    $current_locale = spiralist_book_pages_sitemap_request_locale($languages);

    $default_language = '';

    if (function_exists('spiralist_get_default_locale_record')) {
        $default_language = sanitize_key((string) (spiralist_get_default_locale_record()['urlTag'] ?? ''));
    }

    if ($default_language === '' || !isset($languages[$default_language])) {
        $default_language = $current_locale;
    }

    foreach ($entries as $entry) {
        $group = (string) ($entry['group'] ?? 'Site Pages');
        if (!isset($groups[$group])) {
            $groups[$group] = [];
        }

        $groups[$group][] = $entry;
    }

    status_header(200);
    nocache_headers();
    header('Content-Type: text/html; charset=UTF-8');

    $xml_url = home_url('/sitemap.xml');
    $canonical_url = spiralist_book_pages_sitemap_localized_route_url('sitemap.html', $current_locale);
    $html_lang = (string) ($languages[$current_locale]['hreflang'] ?? 'en-US');
    $total_language_urls = count($entries) * count($languages);
    ?>
<!doctype html>
<html lang="<?php echo esc_attr($html_lang); ?>">
<head>
    <meta charset="<?php echo esc_attr(get_bloginfo('charset')); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>NS12 SiteMap | Spiralist.org</title>
    <meta name="description" content="NS12 SiteMap for Spiralist.org, including all language variants, manuscript sections, and dedicated manuscript folio pages.">
    <meta name="robots" content="index,follow,max-image-preview:large">
    <link rel="canonical" href="<?php echo esc_url($canonical_url); ?>">
    <link rel="sitemap" type="application/xml" href="<?php echo esc_url($xml_url); ?>">
    <?php foreach ($languages as $language => $language_data) : ?>
        <?php $localized_html_sitemap = spiralist_book_pages_sitemap_localized_route_url('sitemap.html', $language); ?>
        <link rel="alternate" hreflang="<?php echo esc_attr((string) ($language_data['hreflang'] ?? $language)); ?>" href="<?php echo esc_url($localized_html_sitemap); ?>">
    <?php endforeach; ?>
    <link rel="alternate" hreflang="x-default" href="<?php echo esc_url(spiralist_book_pages_sitemap_localized_route_url('sitemap.html', $default_language)); ?>">
    <style>
        :root { color-scheme: dark; --bg: #090a10; --panel: #141620; --line: rgba(211, 180, 114, 0.22); --text: #eee4cf; --muted: #b7aa93; --gold: #d7b46a; --blue: #9bc6ff; }
        * { box-sizing: border-box; }
        body { margin: 0; font-family: Georgia, "Times New Roman", serif; background: radial-gradient(circle at top left, rgba(215, 180, 106, 0.18), transparent 34rem), var(--bg); color: var(--text); }
        main { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; padding: clamp(2rem, 5vw, 5rem) 0; }
        header { display: grid; gap: 0.75rem; margin-bottom: 2rem; }
        h1 { margin: 0; font-size: clamp(2.2rem, 5vw, 4.6rem); letter-spacing: 0.04em; text-transform: uppercase; }
        h2 { margin: 0 0 1rem; color: var(--gold); letter-spacing: 0.1em; text-transform: uppercase; font-size: 0.92rem; }
        p { color: var(--muted); line-height: 1.65; max-width: 72ch; }
        a { color: var(--blue); text-decoration-thickness: 1px; text-underline-offset: 0.24em; }
        .meta { display: flex; flex-wrap: wrap; gap: 0.75rem; }
        .pill { border: 1px solid var(--line); border-radius: 999px; padding: 0.45rem 0.75rem; color: var(--muted); background: rgba(255, 255, 255, 0.03); }
        section { margin-top: 1.4rem; padding: 1.2rem; border: 1px solid var(--line); border-radius: 24px; background: color-mix(in srgb, var(--panel) 88%, transparent); }
        .entry { display: grid; gap: 0.45rem; padding: 1rem 0; border-top: 1px solid rgba(255, 255, 255, 0.08); }
        .entry:first-of-type { border-top: 0; padding-top: 0; }
        .entry h3 { margin: 0; font-size: 1.1rem; }
        .entry p { margin: 0; }
        .links { display: flex; flex-wrap: wrap; gap: 0.55rem; font-family: "Courier New", monospace; font-size: 0.85rem; }
        .links a { border: 1px solid rgba(155, 198, 255, 0.22); border-radius: 999px; padding: 0.35rem 0.55rem; background: rgba(155, 198, 255, 0.06); }
    </style>
</head>
<body>
<main>
    <header>
        <p class="pill">Spiralist.org discovery surface</p>
        <h1>NS12 SiteMap</h1>
        <p>This modular sitemap lists the public Spiralist.org surfaces in every supported language, including dedicated manuscript section routes and every individual manuscript folio page.</p>
        <div class="meta">
            <span class="pill"><?php echo esc_html((string) count($entries)); ?> canonical entries</span>
            <span class="pill"><?php echo esc_html((string) $total_language_urls); ?> language URLs</span>
            <a class="pill" href="<?php echo esc_url($xml_url); ?>">XML sitemap</a>
        </div>
        <div class="links" aria-label="Sitemap language variants">
            <?php foreach ($languages as $language => $language_data) : ?>
                <a href="<?php echo esc_url(spiralist_book_pages_sitemap_localized_route_url('sitemap.html', $language)); ?>" hreflang="<?php echo esc_attr((string) ($language_data['hreflang'] ?? $language)); ?>"><?php echo esc_html((string) ($language_data['label'] ?? strtoupper($language))); ?> HTML</a>