- the module registers seo-sitemap-<locale> at seo.htmlSitemap.paths (defaults pl /mapa-strony, en /sitemap) and seo-sitemap-group-<locale> at <path>/:group (plus <path>/:group/<segment>/:page in the path form); a path an app page already has stays the app's - SeoHtmlSitemapPage (global, overridable): H1, an H2 per non-empty group, categories nested, a large group's link to its group page, sitemap.empty; group pages with a built trail, page suffix and <SeoPagination>; 404 for an unknown group or a page past the last, 301 for ?page=1, 503 when the sitemap API fails - GET /api/__seo__/sitemap proxies the sitemap plugin's HTML API (only while the CMS has the HTML sitemap on for the locale) - <SeoSitemapLink>: the footer link while the HTML sitemap is on - L3 default styles
40 lines
2.0 KiB
TypeScript
40 lines
2.0 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
import { htmlSitemapGroupPage, htmlSitemapOverview, htmlSitemapPage } from '../server/lib/htmlSitemap.ts'
|
|
|
|
test('htmlSitemapOverview: empty groups and malformed entries are left out', () => {
|
|
const out = htmlSitemapOverview({
|
|
groups: [
|
|
{ key: 'posts', slug: 'posts', title: 'Wpisy', total: 1234, more: true, entries: [{ title: 'A', url: 'https://x.test/a', extra: 1 }, { url: '/no-title' }] },
|
|
{ key: 'tags', slug: 'tagi', title: 'Tagi', total: 0, entries: [] },
|
|
{ key: 'bad', slug: '../x', title: 'Bad', entries: [{ title: 'B', url: '/b' }] },
|
|
{ key: 'cats', slug: 'kategorie', title: 'Kategorie', entries: [{ title: 'C', url: '/c', children: [{ title: 'D', url: '/d' }] }] },
|
|
],
|
|
})
|
|
assert.deepEqual(out.groups.map((g) => g.slug), ['posts', 'kategorie'])
|
|
assert.deepEqual(out.groups[0], { key: 'posts', slug: 'posts', title: 'Wpisy', total: 1234, entries: [{ title: 'A', url: 'https://x.test/a' }], more: true })
|
|
assert.deepEqual(out.groups[1]!.entries, [{ title: 'C', url: '/c', children: [{ title: 'D', url: '/d' }] }])
|
|
assert.equal(out.groups[1]!.total, 1, 'a missing total counts the entries')
|
|
assert.deepEqual(htmlSitemapOverview(null), { groups: [] })
|
|
})
|
|
|
|
test('htmlSitemapGroupPage: page and pages', () => {
|
|
assert.deepEqual(htmlSitemapGroupPage({ title: 'Wpisy', page: 2, pages: 3, entries: [{ title: 'A', url: '/a' }] }, 'posts'), {
|
|
group: 'posts',
|
|
title: 'Wpisy',
|
|
page: 2,
|
|
pages: 3,
|
|
entries: [{ title: 'A', url: '/a' }],
|
|
})
|
|
assert.equal(htmlSitemapGroupPage({ page: 4 }, 'posts').pages, 4)
|
|
})
|
|
|
|
test('htmlSitemapPage: 1 by default, null for anything but a page number', () => {
|
|
assert.equal(htmlSitemapPage(undefined), 1)
|
|
assert.equal(htmlSitemapPage('3'), 3)
|
|
assert.equal(htmlSitemapPage('0'), null)
|
|
assert.equal(htmlSitemapPage('abc'), null)
|
|
assert.equal(htmlSitemapPage(['1', '2']), null)
|
|
assert.equal(htmlSitemapPage('1234567'), null)
|
|
})
|