feat(ssr): load initial data and SEO for public detail pages
Fetch initial content server-side for detail views and Life feed. Bind detail-specific SEO head tags during SSR. Extract resolvedSeoHead to share head tag generation.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { computed, ref } from 'vue';
|
||||
import { onLocaleChange } from '../src/i18n';
|
||||
import { applyRouteSeo, onSeoChange, resolveRouteSeo, setSeoTranslator, type ResolvedSeoConfig } from '../src/seo';
|
||||
import { applyRouteSeo, onSeoChange, resolvedSeoHead, resolveRouteSeo, setSeoTranslator, type ResolvedSeoConfig } from '../src/seo';
|
||||
|
||||
export default defineNuxtPlugin(() => {
|
||||
const router = useRouter();
|
||||
@@ -8,38 +8,7 @@ export default defineNuxtPlugin(() => {
|
||||
const t = (nuxtApp.$pokopiaI18n as { global: { t: (key: string, values?: Record<string, string | number>) => string } }).global.t;
|
||||
const dynamicSeo = ref<ResolvedSeoConfig | null>(null);
|
||||
const activeSeo = computed(() => dynamicSeo.value ?? resolveRouteSeo(router.currentRoute.value, t));
|
||||
const structuredDataJson = computed(() => JSON.stringify(activeSeo.value.structuredData).replace(/</g, '\\u003C'));
|
||||
|
||||
useHead(() => ({
|
||||
title: activeSeo.value.title,
|
||||
htmlAttrs: {
|
||||
lang: activeSeo.value.locale
|
||||
},
|
||||
meta: [
|
||||
{ key: 'description', name: 'description', content: activeSeo.value.description },
|
||||
{ key: 'robots', name: 'robots', content: activeSeo.value.robots },
|
||||
{ key: 'twitter-card', name: 'twitter:card', content: 'summary_large_image' },
|
||||
{ key: 'twitter-title', name: 'twitter:title', content: activeSeo.value.title },
|
||||
{ key: 'twitter-description', name: 'twitter:description', content: activeSeo.value.description },
|
||||
{ key: 'twitter-image', name: 'twitter:image', content: activeSeo.value.imageUrl },
|
||||
{ key: 'og-site-name', property: 'og:site_name', content: 'Pokopia Wiki' },
|
||||
{ key: 'og-type', property: 'og:type', content: 'website' },
|
||||
{ key: 'og-title', property: 'og:title', content: activeSeo.value.title },
|
||||
{ key: 'og-description', property: 'og:description', content: activeSeo.value.description },
|
||||
{ key: 'og-url', property: 'og:url', content: activeSeo.value.canonicalUrl },
|
||||
{ key: 'og-image', property: 'og:image', content: activeSeo.value.imageUrl },
|
||||
{ key: 'og-locale', property: 'og:locale', content: activeSeo.value.locale === 'en' ? 'en_US' : activeSeo.value.locale.replace('-', '_') }
|
||||
],
|
||||
link: [{ key: 'canonical', rel: 'canonical', href: activeSeo.value.canonicalUrl }],
|
||||
script: [
|
||||
{
|
||||
key: 'pokopia-structured-data',
|
||||
id: 'pokopia-structured-data',
|
||||
type: 'application/ld+json',
|
||||
innerHTML: structuredDataJson.value
|
||||
}
|
||||
]
|
||||
}));
|
||||
useHead(() => resolvedSeoHead(activeSeo.value));
|
||||
|
||||
if (import.meta.server) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user