Files
vue-journal-layer/app/journal-pages/SearchPage.vue
Jakub Zych 289d031201 feat!: render the post page on the shared SEO layer with one H1 in both Journal H1 modes (tracer)
- extend vue-seo-layer (link dependency during development) and drop
  @nuxtjs/seo: the page head, canonical and the one JSON-LD graph come
  from the CMS resolve answer; the post's own title, excerpt and image
  apply only while there is no CMS answer
- remove the journal sitemap source and the copied shared purge route,
  library and plugin (the SEO layer serves POST /api/__site__/cache/purge);
  the deprecated POST /api/__journal__/cache/purge keeps working
- post title is h1 while the Journal API reports content_h1_to_h2 on
  (or absent) and p.journal-post__title while off; journal.postTitleTag
  ('auto' | 'h1' | 'p') overrides it; body h1 headings are demoted to h2
  while the setting is on (gateJournalHtml/sanitizeJournalHtml demoteH1)
- journal.breadcrumbs option and post-title CSS tokens
- smoke harness: count=, header=, noheader= and resolves lines; the
  fixture API also answers the SEO resolve and site endpoints

BREAKING CHANGE: the layer no longer installs @nuxtjs/seo (no
nuxt-site-config, nuxt-schema-org, robots or sitemap module, no
/api/__sitemap__/journal source, no useSiteConfig()); apps take their
head, sitemaps and robots from the SEO plugin through vue-seo-layer.
2026-11-04 13:37:11 +01:00

79 lines
3.6 KiB
Vue

<script setup lang="ts">
// journal-search: the posts matching ?q, paginated with ?page=N, in the API's
// relevance order (no sort is sent). Rendered on the server, so the form and
// the results work without JS. The module keeps the page out of the route
// cache; the page meta marks it noindex, follow (the SEO layer's route
// robots, which win over the CMS's and also leave it out of the route
// report). An invalid or out-of-range page is a real 404.
import { JOURNAL_SEARCH_MIN_LENGTH } from '../utils/client.ts'
import { pageOutOfRange, parsePageParam } from '../utils/pagination.ts'
import { pluralForm, searchTermFromQuery, searchTermState } from '../utils/search.ts'
import { listTitle } from '../utils/seo.ts'
import { toListPost } from '../utils/view.ts'
import type { JournalModuleOptions } from '../utils/types.ts'
definePageMeta({ key: (route) => route.fullPath, seo: { robots: 'noindex, follow' } })
const route = useRoute()
const api = useJournalApi()
const { t, localeProperties } = useI18n()
const cfg = useRuntimeConfig().public.journal as JournalModuleOptions
const q = searchTermFromQuery(route.query.q)
const termState = searchTermState(q)
const page = parsePageParam(route.query.page)
if (page === null) throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
const { data, error } = await useAsyncData(`journal-search-${q}-${page}`, async () => {
if (termState !== 'ready') return null
const posts = await api.listPosts({ search: q, page, perPage: cfg.perPage.search ?? cfg.perPage.index })
return { ...posts, data: posts.data.map(toListPost) }
})
if (error.value) {
throw createError({ statusCode: (error.value as { statusCode?: number }).statusCode ?? 500, fatal: true })
}
if (data.value && pageOutOfRange(page, data.value.meta.last_page)) {
throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
}
const total = data.value?.meta.total ?? 0
const count = t(`journal.search.count.${pluralForm(localeProperties.value.language ?? 'en', total)}`, { count: total })
const heading = q ? t('journal.search.titleQuery', { query: q }) : t('journal.search.title')
const title = listTitle(heading, page, t('journal.pagination.pageTitle', { page }))
useSeoMeta({ title, ogTitle: title })
const term = ref(q)
const onSubmit = () => {
const value = term.value.trim()
return navigateTo({ path: route.path, query: value ? { q: value } : {} })
}
</script>
<template>
<section class="journal-search-page">
<header class="journal-index-header">
<h1 class="journal-index-header__title">{{ title }}</h1>
</header>
<form class="journal-search-page__form" role="search" method="get" :action="route.path" @submit.prevent="onSubmit">
<input
v-model="term"
class="journal-search-page__input"
type="search"
name="q"
:aria-label="$t('journal.search.input')"
:placeholder="$t('journal.search.placeholder')"
/>
<button type="submit" class="journal-search-page__submit">{{ $t('journal.search.submit') }}</button>
</form>
<p v-if="termState === 'empty'" class="journal-search-page__message">{{ $t('journal.search.prompt') }}</p>
<p v-else-if="termState === 'short'" class="journal-search-page__message">
{{ $t('journal.search.short', { min: JOURNAL_SEARCH_MIN_LENGTH }) }}
</p>
<template v-else-if="data">
<p v-if="total > 0" class="journal-search-page__count">{{ count }}</p>
<JournalPostList :posts="data.data" :empty="$t('journal.search.none', { query: q })" />
<JournalPagination :current="data.meta.current_page" :last="data.meta.last_page" />
</template>
</section>
</template>