feat: CMS head and one JSON-LD graph on every server-rendered page (tracer)
- Nitro middleware resolves page requests once and hands the answer to the render (event.context.seo); the route middleware reuses it - useCmsSeo: html lang, hreflang links, og:locale and exactly one JSON-LD script with one @graph (CMS nodes plus useSchemaNode nodes, merged by @id) - local module (configKey seo): cms (alias of public.seo.enabled), breadcrumbs, links.newTabHint, rootFiles, resolveFiles - GET /api/__seo__/resolve for client navigation through the Nuxt server - smoke harness: count=, exact header=, noheader=, reqheader=, repeated options, resolves/apicalls/noreport lines, --no-site; v0.1.1 suite runs unchanged against a backend without /site
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
// One head entry for the whole app, following the resolve answer of the
|
||||
// current page. tagPriority 'critical' makes its tags win over the same
|
||||
// tags a page or another module sets (unhead keeps the lower weight), so
|
||||
// editor values from the SEO plugin override the content defaults; a value
|
||||
// the answer lacks leaves the page's own tag in place.
|
||||
// current page (useCmsSeo). tagPriority 'critical' makes its tags win over
|
||||
// the same tags a page or another module sets (unhead keeps the lower
|
||||
// weight), so editor values from the SEO plugin override the content
|
||||
// defaults; a value the answer lacks leaves the page's own tag in place.
|
||||
//
|
||||
// The answer comes from the route middleware (seo.global.ts): during SSR it
|
||||
// is the one the Nitro middleware already resolved (event.context.seo), kept
|
||||
// in useState so hydration fetches nothing; on client navigation it is
|
||||
// fetched again.
|
||||
|
||||
import { seoHeadInput } from '../utils/seo.ts'
|
||||
import { seoEnabled } from '../utils/seo.ts'
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
const config = useRuntimeConfig()
|
||||
if ((config.public.seo as { enabled?: boolean } | undefined)?.enabled === false) return
|
||||
const answer = useSeoAnswer()
|
||||
const origin = useRequestURL().origin
|
||||
useHead(computed(() => seoHeadInput(answer.value, origin)), { tagPriority: 'critical' })
|
||||
if (!seoEnabled(config.public.seo)) return
|
||||
useCmsSeo(useSeoAnswer())
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user