feat: HTML sitemap pages and footer link
- 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
This commit is contained in:
@@ -7,4 +7,6 @@
|
||||
404 /robots.txt noheader=Retry-After
|
||||
404 /sitemap-posts-1.xml
|
||||
404 /google0123.html
|
||||
# The HTML sitemap with the backend down is a 503 (never an empty page).
|
||||
503 /mapa-strony
|
||||
apicalls 0
|
||||
|
||||
@@ -10,3 +10,7 @@ log [vue-seo-layer] drift: the CMS's journal-post URLs (/wpisy/:slug) match no N
|
||||
log [vue-seo-layer] drift: the CMS paginates in the path form, the layer was built with query (seo.pagination.form):1
|
||||
log [vue-seo-layer] drift: the CMS serves the pl HTML sitemap at /mapa, the layer at /mapa-strony (seo.htmlSitemap.paths):1
|
||||
routereport 0
|
||||
|
||||
# The site answer here has no en path either way; the pl link follows the
|
||||
# layer's path.
|
||||
200 /blog/lwia-grzywa contains=<a href="/mapa-strony" class="seo-sitemap-link">
|
||||
|
||||
@@ -9,5 +9,8 @@
|
||||
404 /google1234.html
|
||||
404 /google0123.html
|
||||
404 /kontakt
|
||||
# The layer's HTML sitemap pages and footer link need the CMS.
|
||||
404 /mapa-strony
|
||||
200 /plain notcontains=seo-sitemap-link
|
||||
apicalls 0
|
||||
noreport /kontakt
|
||||
|
||||
@@ -82,7 +82,7 @@ noreport /stary
|
||||
# The route report at server start: the static paths with the token, not
|
||||
# the signed-in page, the page with a noindex seo.robots or the declared
|
||||
# noindex route. The build matches the site answer: no drift warning.
|
||||
routereport 1 has=/ has=/blog has=/plain has=/about lacks=/konto lacks=/szkic lacks=/prywatne
|
||||
routereport 1 has=/ has=/blog has=/plain has=/about lacks=/konto lacks=/szkic lacks=/prywatne lacks=/mapa-strony
|
||||
log [vue-seo-layer] drift::0
|
||||
|
||||
# L1 breadcrumbs: a layout instance (app.vue) and a page instance render
|
||||
@@ -102,3 +102,26 @@ log [vue-seo-layer] drift::0
|
||||
200 /blog?page=5 contains=<link rel="prev" href="/blog?page=4" contains=<link rel="next" href="/blog?page=6" contains=<title>Blog – strona 5 z 14 | Example</title> contains=content="Wpisy o grzybach, strona 5 z 14" notcontains=z %pages% |</title> notcontains=content="Wpisy o grzybach, strona 5 z %pages%"
|
||||
200 /blog?page=14&sort=new contains=<a class="seo-pagination__prev" href="/blog?sort=new&page=13" rel="prev"> count=seo-pagination__next:0 count=rel="next":0
|
||||
200 /blog?pages=1 count=seo-pagination:0 count=rel="prev":0
|
||||
|
||||
# L3 HTML sitemap: H1, one H2 per non-empty group (the empty one left out),
|
||||
# the category tree nested, a large group's link to its group page; a URL
|
||||
# that is not http(s) renders as text; long titles stay whole.
|
||||
200 /mapa-strony contains=<h1 class="seo-sitemap__title">Mapa strony</h1> count=<h2:3 notcontains=Tagi contains=<a href="/mapa-strony/posts" class="">Wpisy: wszystkie (1234)</a> notcontains=href="javascript: notcontains=<script>alert
|
||||
200 /mapa-strony contains=Grzyby</a><ul class="seo-sitemap__list"> contains=<a href="/grzyby/lecznicze" contains=musi się zawinąć</a> count=<h1:1
|
||||
# A group page: built trail, H1 with the page suffix, pagination; ?page=1
|
||||
# is a 301 to the unnumbered URL; an unknown group or a page past the last
|
||||
# is a 404; a failing sitemap API is a 503 (never an empty cached page).
|
||||
200 /mapa-strony/posts?page=2 contains=<h1 class="seo-sitemap__title">Mapa strony: Wpisy · Strona 2</h1> contains=<a class="seo-breadcrumbs__link" href="/mapa-strony">Mapa strony</a> contains=<span class="seo-breadcrumbs__current" aria-current="page">Wpisy</span> count=<nav class="seo-breadcrumbs":1 count=<nav class="seo-pagination":1 contains=href="/mapa-strony/posts?page=3"
|
||||
200 /mapa-strony/posts contains=<h1 class="seo-sitemap__title">Mapa strony: Wpisy</h1> contains=Lwia grzywa
|
||||
301 /mapa-strony/posts?page=1 header=Location: /mapa-strony/posts
|
||||
404 /mapa-strony/nope
|
||||
404 /mapa-strony/posts?page=9
|
||||
404 /mapa-strony/posts?page=abc
|
||||
503 /mapa-strony/fail
|
||||
# Every group empty: the empty message (en labels on the en path).
|
||||
200 /en/sitemap contains=<h1 class="seo-sitemap__title">Sitemap</h1> contains=<p class="seo-sitemap__empty">There are no pages to list yet.</p> count=<h2:0
|
||||
# A locale the CMS has no HTML sitemap path for.
|
||||
404 /sitemap
|
||||
|
||||
# L4: the footer link to the locale's HTML sitemap.
|
||||
200 /blog/lwia-grzywa contains=<footer><a href="/mapa-strony" class="seo-sitemap-link">Mapa strony</a></footer>
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
// GET /_sitemap/files/<file> <dir>/seo/root/<file>, else 404;
|
||||
// sitemap-fail-*.xml answers 500
|
||||
// GET /_sitemap/indexnow/<key>.txt <dir>/seo/indexnow/<key>.txt, else 404
|
||||
// GET /_sitemap/api/v1/html?locale= the HTML sitemap overview from
|
||||
// <dir>/seo/html.json (overview.<locale>),
|
||||
// else 404
|
||||
// GET /_sitemap/api/v1/html/<group> one group page (groups.<locale>.<group>.<page>,
|
||||
// ?locale=&page= page 1 by default), else 404; the
|
||||
// group fail answers 500
|
||||
//
|
||||
// It records every request (with the parsed JSON body of a POST) so a smoke
|
||||
// run can assert header forwarding, resolve counts and the 404 reports.
|
||||
@@ -65,7 +71,10 @@ export function startFixtureApi({ dir, port = 0, token = FIXTURE_NOTFOUND_TOKEN,
|
||||
let answers = {}
|
||||
/** @type {unknown} */
|
||||
let siteAnswer = null
|
||||
/** @type {any} */
|
||||
let html = {}
|
||||
const load = () => {
|
||||
html = readJson(join(dir, 'seo', 'html.json')) ?? {}
|
||||
answers = { ...(readJson(join(dir, 'resolve.json')) ?? {}), ...(readJson(join(dir, 'seo', 'resolve.json')) ?? {}) }
|
||||
siteAnswer = site ? readJson(join(dir, 'seo', siteFile)) : null
|
||||
}
|
||||
@@ -90,6 +99,13 @@ export function startFixtureApi({ dir, port = 0, token = FIXTURE_NOTFOUND_TOKEN,
|
||||
if (files && req.method === 'GET') return fileAnswer(join(dir, 'seo', 'root', files[1]), files[1])
|
||||
const key = /^\/_sitemap\/indexnow\/([A-Za-z0-9-]{8,128}\.txt)$/.exec(url.pathname)
|
||||
if (key && req.method === 'GET') return fileAnswer(join(dir, 'seo', 'indexnow', key[1]), key[1])
|
||||
const htmlGroup = /^\/_sitemap\/api\/v1\/html(?:\/([a-z0-9-]+))?$/.exec(url.pathname)
|
||||
if (htmlGroup && req.method === 'GET') {
|
||||
const locale = url.searchParams.get('locale') ?? ''
|
||||
if (htmlGroup[1] === 'fail') return { status: 500, body: { error: 'backend failure' } }
|
||||
const hit = htmlGroup[1] ? html.groups?.[locale]?.[htmlGroup[1]]?.[url.searchParams.get('page') ?? '1'] : html.overview?.[locale]
|
||||
return hit ? { status: 200, body: hit } : { status: 404, body: { error: 'not_found' } }
|
||||
}
|
||||
if (!url.pathname.startsWith(PREFIX + '/')) return { status: 404, body: { error: 'not_found' } }
|
||||
const path = url.pathname.slice(PREFIX.length)
|
||||
if (path === '/resolve' && req.method === 'GET') {
|
||||
|
||||
127
testing/fixtures/seo/html.json
Normal file
127
testing/fixtures/seo/html.json
Normal file
@@ -0,0 +1,127 @@
|
||||
{
|
||||
"overview": {
|
||||
"pl": {
|
||||
"groups": [
|
||||
{
|
||||
"key": "pages",
|
||||
"slug": "strony",
|
||||
"title": "Strony",
|
||||
"total": 2,
|
||||
"more": false,
|
||||
"entries": [
|
||||
{
|
||||
"title": "O nas",
|
||||
"url": "https://example.test/about"
|
||||
},
|
||||
{
|
||||
"title": "Kontakt",
|
||||
"url": "https://example.test/kontakt"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "categories",
|
||||
"slug": "kategorie",
|
||||
"title": "Kategorie",
|
||||
"total": 3,
|
||||
"more": false,
|
||||
"entries": [
|
||||
{
|
||||
"title": "Grzyby",
|
||||
"url": "https://example.test/grzyby",
|
||||
"children": [
|
||||
{
|
||||
"title": "Lecznicze",
|
||||
"url": "https://example.test/grzyby/lecznicze"
|
||||
},
|
||||
{
|
||||
"title": "Bardzo długa nazwa kategorii, która nie mieści się w jednej kolumnie i musi się zawinąć",
|
||||
"url": "https://example.test/grzyby/dluga"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "posts",
|
||||
"slug": "posts",
|
||||
"title": "Wpisy",
|
||||
"total": 1234,
|
||||
"more": true,
|
||||
"entries": [
|
||||
{
|
||||
"title": "Lwia grzywa",
|
||||
"url": "https://example.test/blog/lwia-grzywa"
|
||||
},
|
||||
{
|
||||
"title": "<script>alert(1)</script>",
|
||||
"url": "javascript:alert(1)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "tags",
|
||||
"slug": "tagi",
|
||||
"title": "Tagi",
|
||||
"total": 0,
|
||||
"more": false,
|
||||
"entries": []
|
||||
}
|
||||
]
|
||||
},
|
||||
"en": {
|
||||
"groups": [
|
||||
{
|
||||
"key": "pages",
|
||||
"slug": "pages",
|
||||
"title": "Pages",
|
||||
"total": 0,
|
||||
"more": false,
|
||||
"entries": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"groups": {
|
||||
"pl": {
|
||||
"posts": {
|
||||
"1": {
|
||||
"group": "posts",
|
||||
"title": "Wpisy",
|
||||
"page": 1,
|
||||
"pages": 3,
|
||||
"entries": [
|
||||
{
|
||||
"title": "Lwia grzywa",
|
||||
"url": "https://example.test/blog/lwia-grzywa"
|
||||
}
|
||||
]
|
||||
},
|
||||
"2": {
|
||||
"group": "posts",
|
||||
"title": "Wpisy",
|
||||
"page": 2,
|
||||
"pages": 3,
|
||||
"entries": [
|
||||
{
|
||||
"title": "Soplówka",
|
||||
"url": "https://example.test/blog/soplowka"
|
||||
}
|
||||
]
|
||||
},
|
||||
"3": {
|
||||
"group": "posts",
|
||||
"title": "Wpisy",
|
||||
"page": 3,
|
||||
"pages": 3,
|
||||
"entries": [
|
||||
{
|
||||
"title": "Reishi",
|
||||
"url": "https://example.test/blog/reishi"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user