Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(update): improve content integration #1534

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ export default defineNuxtConfig(() => {
}
},

runtimeConfig: {
isDev,
public: {
general: {
url: getWebsiteHost()
}
}
},

devServer: {
port: getPort(),
host: getHost()
Expand Down Expand Up @@ -314,6 +323,14 @@ function getBaseUrl() {
return process.env.npm_config_base_url || process.env.BASE_URL || '/';
}

function getWebsiteHost() {
return (
process.env.npm_config_website_host ||
process.env.WEBSITE_HOST ||
'https://'
);
}

function getHost() {
return process.env.npm_config_host || process.env.HOST || 'localhost';
}
Expand Down
11 changes: 7 additions & 4 deletions src/composables/pageContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ export function usePageContent() {
fetch: async () => {
try {
const path = `/pages${normalizePath(route.path).replace('/index', '')}`;
const {
body: { title, components, i18nParams }
} = await queryCollection('page').path(path).first();
const { components, i18nParams, ...meta } = await queryCollection(
'page'
)
.path(path)
.first()
.then(({ body }) => body);

if (!import.meta.server) {
setI18nParams(i18nParams);
}

return {
components,
pageMeta: { title }
...meta
};
} catch (error) {
console.error(error);
Expand Down
16 changes: 9 additions & 7 deletions src/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<template>
<base-content-container>
<template #before>
<page-header v-bind="layoutData?.body.components.pageHeader" sticky />
<page-header v-bind="layoutData?.components.pageHeader" sticky />
</template>
<template #default>
<page-menu
class="page-menu"
v-bind="layoutData?.body.components.pageMenu"
v-bind="layoutData?.components.pageMenu"
:opened="!preventMenuOpened"
/>
<page-menu-button
v-bind="layoutData?.body.components.pageMenuButton"
v-bind="layoutData?.components.pageMenuButton"
@click="onClickMenuButton"
/>
<slot />
</template>
<template #after>
<page-footer v-bind="layoutData?.body.components.pageFooter" />
<page-footer v-bind="layoutData?.components.pageFooter" />
</template>
</base-content-container>
</template>
Expand Down Expand Up @@ -53,9 +53,11 @@ const { locale } = useI18n();

const { data: layoutData } = await useAsyncData(
`layout-data-${locale.value}`,
async () => {
return queryCollection('layout').path(`/layout/${locale.value}`).first();
},
() =>
queryCollection('layout')
.path(`/layout/${locale.value}`)
.first()
.then(({ body }) => body),
{ watch: [locale] }
);

Expand Down
29 changes: 25 additions & 4 deletions src/pages/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,33 @@
</template>

<script setup>
import { usePageContent, useHead } from '#imports';
import { joinURL } from 'ufo';
import {
useRuntimeConfig,
usePageContent,
useSeoMeta,
// eslint-disable-next-line no-unused-vars
useHead
} from '#imports';

const { fetch } = usePageContent();
const { components, pageMeta } = await fetch();
const { components, title, description, image } = await fetch();

useHead({
title: () => pageMeta.title
const {
app: { baseURL },
public: {
general: { url }
}
} = await useRuntimeConfig();

useSeoMeta({
title: () => title,
ogTitle: () => title,
description: () => description,
ogDescription: () => description,
ogImage: () => joinURL(url, baseURL, image?.src),
ogImageWidth: () => image?.width,
ogImageHeight: () => image?.height,
ogImageType: () => image?.type
});
</script>
Loading