Files
vue-journal-layer/app/journal-pages/PostPage.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

99 lines
4.1 KiB
Vue

<script setup lang="ts">
// journal-post: one published post by slug. An unknown, draft or future post
// is a real 404. The transform sanitizes the body before it reaches the payload.
// Related posts fall back to the latest posts when the API has none (it
// returns none for a post without a category).
//
// One H1 per page in both Journal H1 modes (UI-SPEC L6): while the Journal
// API reports content_h1_to_h2 on (or leaves it out), the title is the h1 and
// the body's h1 headings become h2; while it is off, the title is a
// p.journal-post__title (same class, same look) and the body's own h1 is the
// page's H1. journal.postTitleTag 'h1' or 'p' forces the title's element.
//
// The head comes from the CMS through vue-seo-layer; the post's own title,
// 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 type { JournalModuleOptions } from '../utils/types.ts'
const route = useRoute()
const api = useJournalApi()
const links = useJournalLinks()
const cfg = useRuntimeConfig().public.journal as JournalModuleOptions
const slug = computed(() => String(route.params.slug ?? ''))
const { data: post, error } = await useAsyncData(
() => `journal-post-${slug.value}`,
async () => {
const found = await api.getPost(slug.value)
if (!found) return null
const count = Math.max(0, cfg.relatedCount)
let related = found.related_posts ?? []
if (related.length === 0 && count > 0) {
const latest = await api.listPosts({ perPage: count + 1, sort: cfg.sort })
related = latest.data.filter((p) => p.slug !== found.slug)
}
return { ...found, related_posts: related.slice(0, count).map(toListPost) }
},
{ transform: (p) => (p ? toPostView(p) : null) },
)
if (error.value) {
throw createError({ statusCode: (error.value as { statusCode?: number }).statusCode ?? 500, fatal: true })
}
if (!post.value) {
throw createError({ statusCode: 404, statusMessage: 'Post not found', fatal: true })
}
const answer = useSeoAnswer()
const requestOrigin = useRequestURL().origin
const fallback = computed(() =>
post.value && !cmsHeadPresent(answer.value) ? postSeoMeta(post.value, journalSiteOrigin(answer.value?.url, requestOrigin)) : null,
)
useSeoMeta({
title: () => fallback.value?.title,
ogTitle: () => fallback.value?.ogTitle,
description: () => fallback.value?.description,
ogDescription: () => fallback.value?.ogDescription,
ogType: () => fallback.value?.ogType,
ogImage: () => fallback.value?.ogImage,
articlePublishedTime: () => fallback.value?.articlePublishedTime,
articleModifiedTime: () => fallback.value?.articleModifiedTime,
})
const titleTag = computed(() => journalPostTitleTag(cfg.postTitleTag, post.value?.content_h1_to_h2))
const demoteH1 = computed(() => demotesH1(post.value))
</script>
<template>
<article v-if="post" class="journal-post">
<header class="journal-post__header">
<component :is="titleTag" class="journal-post__title">{{ post.title }}</component>
<JournalPostMeta :post="post" />
</header>
<JournalFeaturedImage :src="post.featured_image_url" :alt="post.title" eager />
<JournalPostBody :html="post.content_html" :demote-h1="demoteH1" />
<nav v-if="post.previous_post || post.next_post" class="journal-post__siblings">
<NuxtLink
v-if="post.previous_post && links.postLink(post.previous_post.slug)"
:to="links.postLink(post.previous_post.slug)!"
rel="prev"
class="journal-post__previous"
>
<span>{{ $t('journal.post.previous') }}</span> {{ post.previous_post.title }}
</NuxtLink>
<NuxtLink
v-if="post.next_post && links.postLink(post.next_post.slug)"
:to="links.postLink(post.next_post.slug)!"
rel="next"
class="journal-post__next"
>
<span>{{ $t('journal.post.next') }}</span> {{ post.next_post.title }}
</NuxtLink>
</nav>
<JournalRelatedPosts :posts="post.related_posts" />
<JournalRssLink />
</article>
</template>