feat: breadcrumbs, CMS pagination and pillar content on page one

- post, index, category, tag and author pages render <SeoBreadcrumbs>
  at the top of their content while journal.breadcrumbs is on (default);
  false leaves the trail to the site's layout, the BreadcrumbList data
  is unchanged
- JournalPagination renders <SeoPagination class-prefix="journal-pagination">
  with the journal's labels: the same class names, plus page 1, the last
  page, gap items, aria labels and head rel prev/next, with links in the
  CMS's pagination form
- with vue-seo-layer's seo.pagination.form 'path' the module registers
  <listing>/<segment>/:page routes (journalPagedRoutes), and the listing
  pages read the page from the :page param or ?page (pageFromRoute)
- the category pillar text renders on page 1 only, the description on
  every page; an h1 in it becomes h2 while the category row's
  content_h1_to_h2 is on (absent counts as on)
This commit is contained in:
Jakub Zych
2026-11-04 13:54:46 +01:00
parent 51e5d67576
commit 98904b8fbd
22 changed files with 239 additions and 56 deletions

View File

@@ -1,7 +1,16 @@
<script setup lang="ts">
// A site that places breadcrumbs in its layout turns the journal pages' own
// off (journal.breadcrumbs false, here NUXT_PUBLIC_JOURNAL_BREADCRUMBS=false)
// and renders one <SeoBreadcrumbs> itself.
const journal = useRuntimeConfig().public.journal as { breadcrumbs?: unknown }
const layoutTrail = journal.breadcrumbs === false || journal.breadcrumbs === 'false'
</script>
<template>
<header class="playground-header">
<JournalSearchBox />
</header>
<div v-if="layoutTrail" class="playground-trail"><SeoBreadcrumbs /></div>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>

View File

@@ -7,7 +7,9 @@ export default defineNuxtConfig({
// purge clears cached pages.
routeRules: { '/**': { swr: 300 } },
// The search page is opt-in; the playground turns it on for the smoke.
journal: { routes: { search: '/search' } },
// One post per category page, so the news category has 12 pages and the
// smoke sees first, last and gap items.
journal: { routes: { search: '/search' }, perPage: { category: 1 } },
i18n: {
strategy: 'prefix_except_default',
defaultLocale: 'en',

View File

@@ -290,6 +290,12 @@
color: var(--journal-color-on-accent);
}
.journal-pagination__gap {
display: inline-block;
padding: var(--journal-space-1) var(--journal-space-2);
color: var(--journal-color-muted);
}
/* Author */
.journal-author-card {
margin-bottom: var(--journal-space-5);

View File

@@ -1,6 +1,9 @@
<script setup lang="ts">
// Heading of a category page: name, description and the category's rich
// content, which goes through the Journal sanitizer before v-html. The page
// content (the pillar text), which goes through the Journal sanitizer before
// v-html. The rich content renders on page 1 only, the description on every
// page (D-41). An h1 in it becomes h2 while the category row's
// content_h1_to_h2 is on (absent counts as on), as for post bodies. The page
// payload keeps embed placeholders; expandEmbeds turns them into iframes as
// the last step, after sanitizing, and its output is never sanitized again.
import type { JournalCategory } from '../../utils/types.ts'
@@ -8,7 +11,9 @@ import { expandEmbeds } from '../../utils/embeds.ts'
import { sanitizeJournalHtml } from '../../utils/htmlGate.ts'
const props = defineProps<{ category: JournalCategory; page?: number }>()
const content = computed(() => expandEmbeds(sanitizeJournalHtml(props.category.content)))
const content = computed(() =>
props.page && props.page > 1 ? '' : expandEmbeds(sanitizeJournalHtml(props.category.content, { demoteH1: props.category.content_h1_to_h2 !== false })),
)
</script>
<template>

View File

@@ -1,33 +1,19 @@
<script setup lang="ts">
// Previous/next and a window of page links for the current listing. Links
// keep the current path and use ?page=N; page 1 drops the query.
import { paginationWindow } from '../../utils/pagination.ts'
const props = defineProps<{ current: number; last: number }>()
const route = useRoute()
const to = (page: number) => {
const query = { ...route.query }
if (page > 1) query.page = String(page)
else delete query.page
return { path: route.path, query }
}
const pages = computed(() => paginationWindow(props.current, props.last))
// Previous/next, page 1, the last page and a window of page links for the
// current listing: vue-seo-layer's <SeoPagination> (UI-SPEC L2) with the
// journal's labels and class names (journal-pagination, __prev, __pages,
// __current, __gap, __next), so app CSS keeps applying. Links follow the
// CMS's pagination form (?page=N or the path form) and page 1 is the
// unnumbered URL; the head gets rel prev/next.
defineProps<{ current: number; last: number }>()
const { t } = useI18n()
const labels = computed(() => ({
label: t('journal.pagination.label'),
previous: t('journal.pagination.previous'),
next: t('journal.pagination.next'),
}))
</script>
<template>
<nav v-if="last > 1" class="journal-pagination" :aria-label="$t('journal.pagination.label')">
<NuxtLink v-if="current > 1" :to="to(current - 1)" rel="prev" class="journal-pagination__prev">
{{ $t('journal.pagination.previous') }}
</NuxtLink>
<ol class="journal-pagination__pages">
<li v-for="page in pages" :key="page">
<span v-if="page === current" class="journal-pagination__current" aria-current="page">{{ page }}</span>
<NuxtLink v-else :to="to(page)">{{ page }}</NuxtLink>
</li>
</ol>
<NuxtLink v-if="current < last" :to="to(current + 1)" rel="next" class="journal-pagination__next">
{{ $t('journal.pagination.next') }}
</NuxtLink>
</nav>
<SeoPagination class-prefix="journal-pagination" :current="current" :last="last" :labels="labels" />
</template>

View File

@@ -3,9 +3,9 @@
// ?page=N. {author} is the author slug, or a login with published posts. An
// unknown author or an out-of-range page is a real 404. When the visitor came
// in by login, the canonical points at the slug URL (a CMS canonical wins).
import { pageOutOfRange, parsePageParam } from '../utils/pagination.ts'
import { pageFromRoute, pageOutOfRange } from '../utils/pagination.ts'
import { absoluteUrl, journalSiteOrigin, listTitle } from '../utils/seo.ts'
import { toListPost } from '../utils/view.ts'
import { journalBreadcrumbsOn, toListPost } from '../utils/view.ts'
import type { JournalModuleOptions } from '../utils/types.ts'
definePageMeta({ key: (route) => route.fullPath })
@@ -17,7 +17,7 @@ const { t } = useI18n()
const cfg = useRuntimeConfig().public.journal as JournalModuleOptions
const param = String(route.params.author ?? '')
const page = parsePageParam(route.query.page)
const page = pageFromRoute(route)
if (page === null) throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
const { data, error } = await useAsyncData(`journal-author-${param}-${page}`, async () => {
@@ -39,6 +39,7 @@ const author = data.value.author
const name = `${author.first_name} ${author.last_name}`.trim() || author.slug
const title = listTitle(t('journal.author.title', { name }), page, t('journal.pagination.pageTitle', { page }))
useSeoMeta({ title, ogTitle: title, ogType: 'profile' })
const crumbs = journalBreadcrumbsOn(cfg.breadcrumbs)
if (author.slug !== param) {
const path = links.authorLink(author.slug)
@@ -51,6 +52,7 @@ if (author.slug !== param) {
<template>
<section v-if="data" class="journal-author">
<SeoBreadcrumbs v-if="crumbs" />
<JournalAuthorCard :author="data.author" :page="page" />
<JournalPostList :posts="data.posts.data" :empty="$t('journal.author.empty')" />
<JournalPagination :current="data.posts.meta.current_page" :last="data.posts.meta.last_page" />

View File

@@ -2,11 +2,14 @@
// journal-category: one category's header and rich content above its posts.
// The slug resolves against GET /categories?include_empty=1, so an empty
// category answers 200 with its content; an unknown slug is a real 404 (this
// route may be a root-level catch-all in the app).
// route may be a root-level catch-all in the app). The rich content (the
// pillar text) shows on page 1 only, the short description on every page
// (D-41); an h1 in it becomes h2 while the category row's content_h1_to_h2
// is on (absent counts as on), like a post body.
import { sanitizeJournalHtml } from '../utils/htmlGate.ts'
import { pageOutOfRange, parsePageParam } from '../utils/pagination.ts'
import { pageFromRoute, pageOutOfRange } from '../utils/pagination.ts'
import { listTitle } from '../utils/seo.ts'
import { toListPost } from '../utils/view.ts'
import { journalBreadcrumbsOn, toListPost } from '../utils/view.ts'
import type { JournalModuleOptions } from '../utils/types.ts'
definePageMeta({ key: (route) => route.fullPath })
@@ -17,7 +20,7 @@ const cfg = useRuntimeConfig().public.journal as JournalModuleOptions
const { t } = useI18n()
const slug = String(route.params.category ?? '')
const page = parsePageParam(route.query.page)
const page = pageFromRoute(route)
if (page === null) throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
const { data, error } = await useAsyncData(`journal-category-${slug}-${page}`, async () => {
@@ -27,7 +30,7 @@ const { data, error } = await useAsyncData(`journal-category-${slug}-${page}`, a
// Only this category reaches the payload, with its content already sanitized.
const { children: _children, ...category } = found
return {
category: { ...category, content: sanitizeJournalHtml(found.content) || null },
category: { ...category, content: sanitizeJournalHtml(found.content, { demoteH1: found.content_h1_to_h2 !== false }) || null },
posts: { ...posts, data: posts.data.map(toListPost) },
}
})
@@ -42,10 +45,12 @@ if (pageOutOfRange(page, data.value.posts.meta.last_page)) {
const title = listTitle(data.value.category.name, page, t('journal.pagination.pageTitle', { page }))
const description = data.value.category.description ?? undefined
useSeoMeta({ title, ogTitle: title, description, ogDescription: description })
const crumbs = journalBreadcrumbsOn(cfg.breadcrumbs)
</script>
<template>
<section v-if="data" class="journal-category">
<SeoBreadcrumbs v-if="crumbs" />
<JournalCategoryHeader :category="data.category" :page="page" />
<JournalPostList :posts="data.posts.data" :empty="$t('journal.category.empty')" />
<JournalPagination :current="data.posts.meta.current_page" :last="data.posts.meta.last_page" />

View File

@@ -1,9 +1,9 @@
<script setup lang="ts">
// journal-index: the post list, paginated with ?page=N. A non-numeric page
// or a page past the last one is a real 404.
import { pageOutOfRange, parsePageParam } from '../utils/pagination.ts'
// journal-index: the post list, paginated with ?page=N (or the path form).
// A non-numeric page or a page past the last one is a real 404.
import { pageFromRoute, pageOutOfRange } from '../utils/pagination.ts'
import { listTitle } from '../utils/seo.ts'
import { toListPost } from '../utils/view.ts'
import { journalBreadcrumbsOn, toListPost } from '../utils/view.ts'
import type { JournalModuleOptions } from '../utils/types.ts'
// Re-run setup (and its 404 checks) on every query change.
@@ -14,7 +14,7 @@ const api = useJournalApi()
const cfg = useRuntimeConfig().public.journal as JournalModuleOptions
const { t } = useI18n()
const page = parsePageParam(route.query.page)
const page = pageFromRoute(route)
if (page === null) throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
const { data, error } = await useAsyncData(
@@ -31,10 +31,12 @@ if (pageOutOfRange(page, data.value.meta.last_page)) {
const title = listTitle(t('journal.index.title'), page, t('journal.pagination.pageTitle', { page }))
useSeoMeta({ title, ogTitle: title })
const crumbs = journalBreadcrumbsOn(cfg.breadcrumbs)
</script>
<template>
<section v-if="data" class="journal-index">
<SeoBreadcrumbs v-if="crumbs" />
<JournalIndexHeader :page="page" />
<JournalPostList :posts="data.data" />
<JournalPagination :current="data.meta.current_page" :last="data.meta.last_page" />

View File

@@ -14,7 +14,7 @@
// excerpt and featured image apply only while there is no CMS answer.
import { cmsHeadPresent, journalPostTitleTag, journalSiteOrigin, postSeoMeta } from '../utils/seo.ts'
import { demotesH1, toPostView } from '../utils/postView.ts'
import { toListPost } from '../utils/view.ts'
import { journalBreadcrumbsOn, toListPost } from '../utils/view.ts'
import type { JournalModuleOptions } from '../utils/types.ts'
const route = useRoute()
@@ -64,10 +64,12 @@ useSeoMeta({
const titleTag = computed(() => journalPostTitleTag(cfg.postTitleTag, post.value?.content_h1_to_h2))
const demoteH1 = computed(() => demotesH1(post.value))
const crumbs = journalBreadcrumbsOn(cfg.breadcrumbs)
</script>
<template>
<article v-if="post" class="journal-post">
<SeoBreadcrumbs v-if="crumbs" />
<header class="journal-post__header">
<component :is="titleTag" class="journal-post__title">{{ post.title }}</component>
<JournalPostMeta :post="post" />

View File

@@ -1,9 +1,9 @@
<script setup lang="ts">
// journal-tag: posts with one tag, paginated with ?page=N. An unknown tag or
// an out-of-range page is a real 404.
import { pageOutOfRange, parsePageParam } from '../utils/pagination.ts'
import { pageFromRoute, pageOutOfRange } from '../utils/pagination.ts'
import { listTitle } from '../utils/seo.ts'
import { toListPost } from '../utils/view.ts'
import { journalBreadcrumbsOn, toListPost } from '../utils/view.ts'
import type { JournalModuleOptions } from '../utils/types.ts'
definePageMeta({ key: (route) => route.fullPath })
@@ -14,7 +14,7 @@ const { t } = useI18n()
const cfg = useRuntimeConfig().public.journal as JournalModuleOptions
const slug = String(route.params.tag ?? '')
const page = parsePageParam(route.query.page)
const page = pageFromRoute(route)
if (page === null) throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
const { data, error } = await useAsyncData(`journal-tag-${slug}-${page}`, async () => {
@@ -34,10 +34,12 @@ if (pageOutOfRange(page, data.value.posts.meta.last_page)) {
const heading = t('journal.tag.title', { name: data.value.tag.name })
const title = listTitle(heading, page, t('journal.pagination.pageTitle', { page }))
useSeoMeta({ title, ogTitle: title })
const crumbs = journalBreadcrumbsOn(cfg.breadcrumbs)
</script>
<template>
<section v-if="data" class="journal-tag">
<SeoBreadcrumbs v-if="crumbs" />
<header class="journal-index-header">
<h1 class="journal-index-header__title">{{ title }}</h1>
</header>

View File

@@ -1,6 +1,7 @@
// Page-number rules for Journal listings. Pages use ?page=N (never a path
// segment). Anything but a positive integer, and any page past the last one,
// is a real 404.
// Page-number rules for Journal listings. Pages use ?page=N, or the path
// form <listing>/<segment>/N when the site's pagination form is path (the
// page route's :page param). Anything but a positive integer, and any page
// past the last one, is a real 404.
/**
* Parses the ?page query value: 1 when absent, the integer for a string of
@@ -15,6 +16,16 @@ export function parsePageParam(raw: unknown): number | null {
return n
}
/**
* The page of a listing route: its :page param in the path form, else the
* ?page query value, parsed as parsePageParam does (null is a 404).
*/
export function pageFromRoute(route: { params?: Record<string, unknown>; query?: Record<string, unknown> }): number | null {
const param = route.params?.page
if (param !== undefined && param !== null && param !== '') return parsePageParam(param)
return parsePageParam(route.query?.page)
}
/**
* True when `page` lies past the last page. Page 1 is always in range, so an
* empty listing renders its empty state instead of a 404.

View File

@@ -79,3 +79,34 @@ export function fillJournalPath(pattern: string, params: Record<string, string |
.join('/')
})
}
/** The listing views that page (the search page keeps ?page with its ?q). */
export const JOURNAL_PAGED_VIEWS: ReadonlyArray<keyof JournalRoutes> = Object.freeze(['index', 'category', 'tag', 'author'])
/** The route name of a listing's path-form page route for one segment. */
export function journalPagedRouteName(key: keyof JournalRoutes, segment: string): string {
return `${JOURNAL_ROUTE_NAMES[key]}-page-${segment}`
}
/**
* The extra listing routes of the path pagination form (D-40): with the
* vue-seo-layer build option seo.pagination.form 'path', each listing gets
* `<listing>/<segment>/:page` for every distinct locale segment
* (seo.pagination.segments, else the param name), rendering the same page
* as the listing. The query form, or no option, adds none.
*/
export function journalPagedRoutes(routes: JournalRoutes, pagination: unknown): Array<{ key: keyof JournalRoutes; name: string; path: string }> {
const p = pagination !== null && typeof pagination === 'object' ? (pagination as Record<string, unknown>) : {}
if (p.form !== 'path') return []
const segment = /^[\p{L}\p{N}_-]+$/u
const raw = p.segments !== null && typeof p.segments === 'object' ? Object.values(p.segments as Record<string, unknown>) : []
const segments = [...new Set(raw.filter((v): v is string => typeof v === 'string' && segment.test(v)))]
if (segments.length === 0) segments.push(typeof p.param === 'string' && segment.test(p.param) ? p.param : 'page')
const out: Array<{ key: keyof JournalRoutes; name: string; path: string }> = []
for (const key of JOURNAL_PAGED_VIEWS) {
const base = routes[key]
if (base === false) continue
for (const seg of segments) out.push({ key, name: journalPagedRouteName(key, seg), path: `${base.replace(/\/+$/, '')}/${seg}/:page(\\d+)` })
}
return out
}

View File

@@ -93,6 +93,12 @@ export interface JournalCategory {
description: string | null
/** Rich HTML body of the category page, stored as is; null when unset. */
content: string | null
/**
* The Journal H1 setting on this row (newer Journal APIs): true while an
* h1 in content becomes h2. Absent on an older Journal, which counts as
* true.
*/
content_h1_to_h2?: boolean
parent_id: number | null
nest_depth: number | null
post_count: number

View File

@@ -26,3 +26,11 @@ export function formatJournalDate(iso: string | null | undefined, language: stri
return new Intl.DateTimeFormat('en', { dateStyle: 'long', timeZone: 'UTC' }).format(d)
}
}
/**
* True while the journal pages render <SeoBreadcrumbs> at the top of their
* content (journal.breadcrumbs, NUXT_PUBLIC_JOURNAL_BREADCRUMBS; default on).
*/
export function journalBreadcrumbsOn(option: unknown): boolean {
return option !== false && option !== 'false'
}

View File

@@ -7,7 +7,7 @@
import { fileURLToPath } from 'node:url'
import { defineNuxtModule, extendPages } from 'nuxt/kit'
import { DEFAULT_JOURNAL_ROUTES, JOURNAL_ROUTE_NAMES, normalizeJournalRoutes } from '../app/utils/routes.ts'
import { DEFAULT_JOURNAL_ROUTES, JOURNAL_ROUTE_NAMES, journalPagedRoutes, normalizeJournalRoutes } from '../app/utils/routes.ts'
import type { JournalModuleOptions, JournalPostTitleTag, JournalRoutes } from '../app/utils/types.ts'
const PAGE_FILES: Record<keyof JournalRoutes, string> = {
@@ -55,12 +55,18 @@ export default defineNuxtModule<JournalModuleOptions>({
setup(options, nuxt) {
const routes = normalizeJournalRoutes(options.routes as unknown as Record<string, unknown>)
// The path pagination form (vue-seo-layer's seo.pagination.form 'path',
// D-40) adds <listing>/<segment>/:page routes rendering the same pages,
// which read the page from the :page param.
const paged = journalPagedRoutes(routes, (nuxt.options as { seo?: { pagination?: unknown } }).seo?.pagination)
extendPages((pages) => {
for (const key of Object.keys(PAGE_FILES) as Array<keyof JournalRoutes>) {
const path = routes[key]
if (path === false) continue
pages.push({ name: JOURNAL_ROUTE_NAMES[key], path, file: `${pagesDir}${PAGE_FILES[key]}.vue` })
}
for (const route of paged) pages.push({ name: route.name, path: route.path, file: `${pagesDir}${PAGE_FILES[route.key]}.vue` })
})
// The search page renders per ?q, so it is never route-cached: Nitro's

View File

@@ -8,7 +8,7 @@
"dev": "nuxi dev .playground",
"build:playground": "nuxt build .playground",
"test": "node --test --test-reporter=tap tests/*.test.ts",
"smoke:ssr": "node testing/smoke-ssr.mjs --output .playground/.output --fixtures testing/fixtures/acme --expect testing/expect-acme.txt && node testing/smoke-ssr.mjs --output .playground/.output --fixtures testing/fixtures/acme --expect testing/expect-acme-title-h1.txt --env NUXT_PUBLIC_JOURNAL_POST_TITLE_TAG=h1 && node testing/smoke-ssr.mjs --output .playground/.output --fixtures testing/fixtures/acme --expect testing/expect-acme-title-p.txt --env NUXT_PUBLIC_JOURNAL_POST_TITLE_TAG=p && node testing/smoke-ssr.mjs --output .playground/.output --fixtures testing/fixtures/acme --expect testing/expect-acme-hint-off.txt --env NUXT_PUBLIC_SEO_LINKS_NEW_TAB_HINT=false",
"smoke:ssr": "node testing/smoke-ssr.mjs --output .playground/.output --fixtures testing/fixtures/acme --expect testing/expect-acme.txt && node testing/smoke-ssr.mjs --output .playground/.output --fixtures testing/fixtures/acme --expect testing/expect-acme-title-h1.txt --env NUXT_PUBLIC_JOURNAL_POST_TITLE_TAG=h1 && node testing/smoke-ssr.mjs --output .playground/.output --fixtures testing/fixtures/acme --expect testing/expect-acme-title-p.txt --env NUXT_PUBLIC_JOURNAL_POST_TITLE_TAG=p && node testing/smoke-ssr.mjs --output .playground/.output --fixtures testing/fixtures/acme --expect testing/expect-acme-hint-off.txt --env NUXT_PUBLIC_SEO_LINKS_NEW_TAB_HINT=false && node testing/smoke-ssr.mjs --output .playground/.output --fixtures testing/fixtures/acme --expect testing/expect-acme-breadcrumbs-off.txt --env NUXT_PUBLIC_JOURNAL_BREADCRUMBS=false",
"dev:prepare": "nuxt prepare .playground",
"check:git-install": "bash scripts/check-git-install.sh"
},

View File

@@ -0,0 +1,6 @@
# SSR expectations with journal.breadcrumbs off
# (NUXT_PUBLIC_JOURNAL_BREADCRUMBS=false, UI-SPEC L1 journal placement
# switch): journal pages render no <SeoBreadcrumbs>; the playground's layout
# renders the one trail; the BreadcrumbList data is unchanged.
200 /blog/hello-acme count=<nav class="seo-breadcrumbs":1 contains=<div class="playground-trail"><nav class="seo-breadcrumbs" notcontains=<article class="journal-post"><nav contains=BreadcrumbList count=application/ld+json:1
200 /blog count=<nav class="seo-breadcrumbs":1 contains=<div class="playground-trail"><nav class="seo-breadcrumbs" notcontains=<section class="journal-index"><nav

View File

@@ -103,3 +103,25 @@
200 /blog/heading-on headings=strict cardlinks=1 count=<h1:1
200 /blog/heading-off headings=strict cardlinks=1 count=<h1:1
200 /blog/uncategorised-note headings=strict cardlinks=1 count=<h1:1
# Breadcrumbs at the top of journal pages (journal.breadcrumbs, default on;
# D-86) from the resolve answer, one per page; the BreadcrumbList stays in
# the one JSON-LD graph.
200 /blog/hello-acme count=<nav class="seo-breadcrumbs":1 contains=<article class="journal-post"><nav class="seo-breadcrumbs" notcontains=playground-trail contains=BreadcrumbList count=application/ld+json:1
200 /blog count=<nav class="seo-breadcrumbs":1 contains=<section class="journal-index"><nav class="seo-breadcrumbs"
# Category pillar text (D-41, the Journal H1 setting per category row): on
# page 1 only, h1 demoted while content_h1_to_h2 is on, kept while off (two
# h1 on that page: the setting's documented consequence); the description
# on every page.
200 /blog/category/news contains=<h2>About Acme news</h2> notcontains=<h1>About Acme news count=<h1:1 headings=strict
200 /blog/category/news?page=2 notcontains=Acme news marker contains=Company news from Acme. count=<h1:1 contains=· Page 2
200 /blog/category/plain contains=<h1>Plain pillar heading</h1> count=<h1:2 contains=A category whose site keeps H1 headings as written.
# Pagination through <SeoPagination class-prefix="journal-pagination"> (L2):
# 12 one-post pages of the news category, page 1 and the last page with gap
# items around the window, rel prev/next links and head links.
200 /blog/category/news?page=6 contains=<nav class="journal-pagination" aria-label="Pagination"> count=journal-pagination__gap:2 contains=<a href="/blog/category/news" aria-label="Page 1">1</a> contains=<a href="/blog/category/news?page=12" aria-label="Page 12">12</a> contains=<span class="journal-pagination__current" aria-current="page">6</span>
200 /blog/category/news?page=6 contains=<a class="journal-pagination__prev" href="/blog/category/news?page=5" rel="prev">Previous page</a> contains=<a class="journal-pagination__next" href="/blog/category/news?page=7" rel="next">Next page</a> contains=<link rel="prev" href="/blog/category/news?page=5" contains=<link rel="next" href="/blog/category/news?page=7"
200 /blog/category/news?page=2 contains=<a class="journal-pagination__prev" href="/blog/category/news" rel="prev">
404 /blog/category/news?page=13

View File

@@ -4,10 +4,11 @@
"name": "News",
"slug": "news",
"description": "Company news from Acme.",
"content": "<h2>About Acme news</h2>\n<p>Acme news marker: every launch, recall and anvil delivery.</p>\n",
"content": "<h1>About Acme news</h1>\n<p>Acme news marker: every launch, recall and anvil delivery.</p>\n",
"parent_id": null,
"nest_depth": 0,
"post_count": 12
"post_count": 12,
"content_h1_to_h2": true
},
{
"id": 2,
@@ -17,6 +18,18 @@
"content": null,
"parent_id": null,
"nest_depth": 0,
"post_count": 0,
"content_h1_to_h2": true
},
{
"id": 3,
"name": "Plain",
"slug": "plain",
"description": "A category whose site keeps H1 headings as written.",
"content": "<h1>Plain pillar heading</h1>\n<p>Plain pillar marker.</p>\n",
"content_h1_to_h2": false,
"parent_id": null,
"nest_depth": 0,
"post_count": 0
}
]

View File

@@ -52,6 +52,29 @@
"mainEntityOfPage": {
"@id": "https://acme.test/blog/hello-acme#webpage"
}
},
{
"@type": "BreadcrumbList",
"@id": "https://acme.test/blog/hello-acme#breadcrumb",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "Home",
"item": "https://acme.test/"
},
{
"@type": "ListItem",
"position": 2,
"name": "Blog",
"item": "https://acme.test/blog"
},
{
"@type": "ListItem",
"position": 3,
"name": "Hello Acme"
}
]
}
]
},

View File

@@ -1,7 +1,7 @@
// ?page=N parsing, out-of-range detection and the page window.
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { pageOutOfRange, paginationWindow, parsePageParam } from '../app/utils/pagination.ts'
import { pageFromRoute, pageOutOfRange, paginationWindow, parsePageParam } from '../app/utils/pagination.ts'
test('a missing page is page 1', () => {
assert.equal(parsePageParam(undefined), 1)
@@ -45,3 +45,12 @@ test('paginationWindow clips to the page count and handles empty input', () => {
assert.deepEqual(paginationWindow(1, 0), [])
assert.deepEqual(paginationWindow(1, 5, 0), [])
})
test('pageFromRoute reads the path-form :page param, else ?page', () => {
assert.equal(pageFromRoute({ params: { page: '3' }, query: { page: '5' } }), 3)
assert.equal(pageFromRoute({ params: {}, query: { page: '5' } }), 5)
assert.equal(pageFromRoute({ params: {}, query: {} }), 1)
assert.equal(pageFromRoute({ params: { page: '0' } }), null)
assert.equal(pageFromRoute({ params: { page: 'x' } }), null)
assert.equal(pageFromRoute({}), 1)
})

View File

@@ -5,6 +5,7 @@ import {
DEFAULT_JOURNAL_ROUTES,
JOURNAL_ROUTE_NAMES,
fillJournalPath,
journalPagedRoutes,
normalizeJournalRoutes,
} from '../app/utils/routes.ts'
@@ -117,3 +118,29 @@ test('fillJournalPath drops a custom matcher and a modifier with the param', ()
test('fillJournalPath leaves unknown params empty', () => {
assert.equal(fillJournalPath('/autor/:author', {}), '/autor/')
})
test('journalPagedRoutes: the path form adds <listing>/<segment>/:page per segment', () => {
const routes = normalizeJournalRoutes({ search: '/search' })
assert.deepEqual(journalPagedRoutes(routes, { form: 'path', param: 'page', segments: { pl: 'strona', en: 'page' } }), [
{ key: 'index', name: 'journal-index-page-strona', path: '/blog/strona/:page(\\d+)' },
{ key: 'index', name: 'journal-index-page-page', path: '/blog/page/:page(\\d+)' },
{ key: 'category', name: 'journal-category-page-strona', path: '/blog/category/:category/strona/:page(\\d+)' },
{ key: 'category', name: 'journal-category-page-page', path: '/blog/category/:category/page/:page(\\d+)' },
{ key: 'tag', name: 'journal-tag-page-strona', path: '/blog/tag/:tag/strona/:page(\\d+)' },
{ key: 'tag', name: 'journal-tag-page-page', path: '/blog/tag/:tag/page/:page(\\d+)' },
{ key: 'author', name: 'journal-author-page-strona', path: '/blog/author/:author/strona/:page(\\d+)' },
{ key: 'author', name: 'journal-author-page-page', path: '/blog/author/:author/page/:page(\\d+)' },
])
})
test('journalPagedRoutes: the query form, no option and disabled views add nothing', () => {
const routes = normalizeJournalRoutes({ tag: false, author: false, category: false })
assert.deepEqual(journalPagedRoutes(routes, { form: 'query' }), [])
assert.deepEqual(journalPagedRoutes(routes, undefined), [])
assert.deepEqual(journalPagedRoutes(routes, { form: 'path' }), [{ key: 'index', name: 'journal-index-page-page', path: '/blog/page/:page(\\d+)' }])
assert.deepEqual(journalPagedRoutes(normalizeJournalRoutes({ index: '/news/' }), { form: 'path', param: 'p', segments: { pl: 'bad/seg' } })[0], {
key: 'index',
name: 'journal-index-page-p',
path: '/news/p/:page(\\d+)',
})
})