feat: fill pages
All checks were successful
Publish Docker Images / build-and-publish (push) Successful in 10m25s
All checks were successful
Publish Docker Images / build-and-publish (push) Successful in 10m25s
This commit is contained in:
35
frontend/app/pages/[...slug].vue
Normal file
35
frontend/app/pages/[...slug].vue
Normal file
@@ -0,0 +1,35 @@
|
||||
<template>
|
||||
<NuxtLayout v-if="page" :name="page.meta?.layout ?? 'default'">
|
||||
<ContentRenderer :value="page" />
|
||||
</NuxtLayout>
|
||||
<div v-else>
|
||||
<h1>Page not found</h1>
|
||||
<p>This page doesn't exist in {{ locale }} language.</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { withLeadingSlash } from 'ufo';
|
||||
import type { Collections } from '@nuxt/content';
|
||||
|
||||
const route = useRoute();
|
||||
const { locale } = useI18n();
|
||||
const slug = computed(() => withLeadingSlash(String(route.params.slug)));
|
||||
|
||||
const { data: page } = await useAsyncData(
|
||||
'page-' + slug.value,
|
||||
async () => {
|
||||
const collection = ('content_' + locale.value) as keyof Collections;
|
||||
const content = await queryCollection(collection).path(slug.value).first();
|
||||
if (!content && locale.value !== 'en') {
|
||||
return await queryCollection('content_en').path(slug.value).first();
|
||||
}
|
||||
return content;
|
||||
},
|
||||
{
|
||||
watch: [locale], // Refresh when locale changes
|
||||
},
|
||||
);
|
||||
|
||||
useMeta({ title: page.value?.title, description: page.value?.description });
|
||||
</script>
|
||||
Reference in New Issue
Block a user