feat(blog): add dynamic blog post rendering with i18n support and error handling in [slug].vue
This commit is contained in:
@@ -2,14 +2,14 @@
|
|||||||
const { locale } = useI18n()
|
const { locale } = useI18n()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
const slug = Array.isArray(route.params.slug) ? route.params.slug.join('/') : route.params.slug
|
const slug = route.params.slug as string
|
||||||
const isFr = locale.value === 'fr'
|
const isFr = locale.value === 'fr'
|
||||||
const collection = isFr ? 'blog_fr' : 'blog_en'
|
|
||||||
// blog_fr prefix = /fr/blog, blog_en prefix = /en/blog (aligned with content.config.ts)
|
|
||||||
const path = isFr ? `/fr/blog/${slug}` : `/en/blog/${slug}`
|
const path = isFr ? `/fr/blog/${slug}` : `/en/blog/${slug}`
|
||||||
|
|
||||||
const { data: page } = await useAsyncData(`blog-${locale.value}-${slug}`, () =>
|
const { data: page } = await useAsyncData(`blog-${locale.value}-${slug}`, () =>
|
||||||
queryCollection(collection).path(path).first()
|
isFr
|
||||||
|
? queryCollection('blog_fr').path(path).first()
|
||||||
|
: queryCollection('blog_en').path(path).first()
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!page.value) {
|
if (!page.value) {
|
||||||
+3
-5
@@ -34,6 +34,7 @@ export default defineNuxtConfig({
|
|||||||
i18n: {
|
i18n: {
|
||||||
strategy: 'prefix',
|
strategy: 'prefix',
|
||||||
defaultLocale: 'fr',
|
defaultLocale: 'fr',
|
||||||
|
baseUrl: 'https://killiandalcin.fr',
|
||||||
locales: [
|
locales: [
|
||||||
{ code: 'fr', language: 'fr-FR', file: 'fr.json' },
|
{ code: 'fr', language: 'fr-FR', file: 'fr.json' },
|
||||||
{ code: 'en', language: 'en-US', file: 'en.json' },
|
{ code: 'en', language: 'en-US', file: 'en.json' },
|
||||||
@@ -42,7 +43,8 @@ export default defineNuxtConfig({
|
|||||||
detectBrowserLanguage: {
|
detectBrowserLanguage: {
|
||||||
useCookie: true,
|
useCookie: true,
|
||||||
cookieKey: 'i18n_redirected',
|
cookieKey: 'i18n_redirected',
|
||||||
redirectOn: 'root',
|
redirectOn: 'no prefix',
|
||||||
|
fallbackLocale: 'fr',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
runtimeConfig: {
|
runtimeConfig: {
|
||||||
@@ -59,10 +61,6 @@ export default defineNuxtConfig({
|
|||||||
gtag: {
|
gtag: {
|
||||||
enabled: !import.meta.dev,
|
enabled: !import.meta.dev,
|
||||||
},
|
},
|
||||||
routeRules: {
|
|
||||||
'/blog': { redirect: { to: '/fr/blog', statusCode: 301 } },
|
|
||||||
'/blog/**': { redirect: { to: '/fr/blog', statusCode: 301 } },
|
|
||||||
},
|
|
||||||
content: {
|
content: {
|
||||||
build: {
|
build: {
|
||||||
markdown: {
|
markdown: {
|
||||||
|
|||||||
Reference in New Issue
Block a user