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 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 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 { 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) {
|
||||
+3
-5
@@ -34,6 +34,7 @@ export default defineNuxtConfig({
|
||||
i18n: {
|
||||
strategy: 'prefix',
|
||||
defaultLocale: 'fr',
|
||||
baseUrl: 'https://killiandalcin.fr',
|
||||
locales: [
|
||||
{ code: 'fr', language: 'fr-FR', file: 'fr.json' },
|
||||
{ code: 'en', language: 'en-US', file: 'en.json' },
|
||||
@@ -42,7 +43,8 @@ export default defineNuxtConfig({
|
||||
detectBrowserLanguage: {
|
||||
useCookie: true,
|
||||
cookieKey: 'i18n_redirected',
|
||||
redirectOn: 'root',
|
||||
redirectOn: 'no prefix',
|
||||
fallbackLocale: 'fr',
|
||||
},
|
||||
},
|
||||
runtimeConfig: {
|
||||
@@ -59,10 +61,6 @@ export default defineNuxtConfig({
|
||||
gtag: {
|
||||
enabled: !import.meta.dev,
|
||||
},
|
||||
routeRules: {
|
||||
'/blog': { redirect: { to: '/fr/blog', statusCode: 301 } },
|
||||
'/blog/**': { redirect: { to: '/fr/blog', statusCode: 301 } },
|
||||
},
|
||||
content: {
|
||||
build: {
|
||||
markdown: {
|
||||
|
||||
Reference in New Issue
Block a user