Skip to content

Commit 8f37e50

Browse files
authored
Merge pull request #1534 from GrabarzUndPartner/feature/update-content-integration
fix(update): improve content integration
2 parents 3c70a18 + 5da8765 commit 8f37e50

File tree

4 files changed

+58
-15
lines changed

4 files changed

+58
-15
lines changed

nuxt.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ export default defineNuxtConfig(() => {
4747
}
4848
},
4949

50+
runtimeConfig: {
51+
isDev,
52+
public: {
53+
general: {
54+
url: getWebsiteHost()
55+
}
56+
}
57+
},
58+
5059
devServer: {
5160
port: getPort(),
5261
host: getHost()
@@ -314,6 +323,14 @@ function getBaseUrl() {
314323
return process.env.npm_config_base_url || process.env.BASE_URL || '/';
315324
}
316325

326+
function getWebsiteHost() {
327+
return (
328+
process.env.npm_config_website_host ||
329+
process.env.WEBSITE_HOST ||
330+
'https://'
331+
);
332+
}
333+
317334
function getHost() {
318335
return process.env.npm_config_host || process.env.HOST || 'localhost';
319336
}

src/composables/pageContent.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ export function usePageContent() {
88
fetch: async () => {
99
try {
1010
const path = `/pages${normalizePath(route.path).replace('/index', '')}`;
11-
const {
12-
body: { title, components, i18nParams }
13-
} = await queryCollection('page').path(path).first();
11+
const { components, i18nParams, ...meta } = await queryCollection(
12+
'page'
13+
)
14+
.path(path)
15+
.first()
16+
.then(({ body }) => body);
1417

1518
if (!import.meta.server) {
1619
setI18nParams(i18nParams);
1720
}
1821

1922
return {
2023
components,
21-
pageMeta: { title }
24+
...meta
2225
};
2326
} catch (error) {
2427
console.error(error);

src/layouts/default.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<template>
22
<base-content-container>
33
<template #before>
4-
<page-header v-bind="layoutData?.body.components.pageHeader" sticky />
4+
<page-header v-bind="layoutData?.components.pageHeader" sticky />
55
</template>
66
<template #default>
77
<page-menu
88
class="page-menu"
9-
v-bind="layoutData?.body.components.pageMenu"
9+
v-bind="layoutData?.components.pageMenu"
1010
:opened="!preventMenuOpened"
1111
/>
1212
<page-menu-button
13-
v-bind="layoutData?.body.components.pageMenuButton"
13+
v-bind="layoutData?.components.pageMenuButton"
1414
@click="onClickMenuButton"
1515
/>
1616
<slot />
1717
</template>
1818
<template #after>
19-
<page-footer v-bind="layoutData?.body.components.pageFooter" />
19+
<page-footer v-bind="layoutData?.components.pageFooter" />
2020
</template>
2121
</base-content-container>
2222
</template>
@@ -53,9 +53,11 @@ const { locale } = useI18n();
5353
5454
const { data: layoutData } = await useAsyncData(
5555
`layout-data-${locale.value}`,
56-
async () => {
57-
return queryCollection('layout').path(`/layout/${locale.value}`).first();
58-
},
56+
() =>
57+
queryCollection('layout')
58+
.path(`/layout/${locale.value}`)
59+
.first()
60+
.then(({ body }) => body),
5961
{ watch: [locale] }
6062
);
6163

src/pages/[...slug].vue

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,33 @@
2020
</template>
2121

2222
<script setup>
23-
import { usePageContent, useHead } from '#imports';
23+
import { joinURL } from 'ufo';
24+
import {
25+
useRuntimeConfig,
26+
usePageContent,
27+
useSeoMeta,
28+
// eslint-disable-next-line no-unused-vars
29+
useHead
30+
} from '#imports';
2431
2532
const { fetch } = usePageContent();
26-
const { components, pageMeta } = await fetch();
33+
const { components, title, description, image } = await fetch();
2734
28-
useHead({
29-
title: () => pageMeta.title
35+
const {
36+
app: { baseURL },
37+
public: {
38+
general: { url }
39+
}
40+
} = await useRuntimeConfig();
41+
42+
useSeoMeta({
43+
title: () => title,
44+
ogTitle: () => title,
45+
description: () => description,
46+
ogDescription: () => description,
47+
ogImage: () => joinURL(url, baseURL, image?.src),
48+
ogImageWidth: () => image?.width,
49+
ogImageHeight: () => image?.height,
50+
ogImageType: () => image?.type
3051
});
3152
</script>

0 commit comments

Comments
 (0)