version update to nuxt4
This commit is contained in:
parent
7f1770d442
commit
ef84942e38
41 changed files with 5134 additions and 4946 deletions
26
app/composables/useGlobal.ts
Normal file
26
app/composables/useGlobal.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import type BaseFile from "~~/types/component/baseFile";
|
||||
import type Footer from "~~/types/component/global/footer";
|
||||
import type Navbar from "~~/types/component/global/navbar";
|
||||
import type SEO from "~~/types/component/global/seo";
|
||||
import type Global from "~~/types/single/global";
|
||||
|
||||
export const useGlobal = () => {
|
||||
const global = useState<Global | null>("global");
|
||||
const runtimeConfig = useRuntimeConfig();
|
||||
const appTitle = runtimeConfig.public.app.title;
|
||||
|
||||
const logo = computed<BaseFile | null>(() => global.value?.logo ?? null);
|
||||
const navbar = computed<Navbar | null>(() => global.value?.navbar ?? null);
|
||||
const footer = computed<Footer | null>(() => global.value?.footer ?? null);
|
||||
const seo = computed<SEO | null>(() => global.value?.SEO ?? null);
|
||||
const title = computed<string>(() => seo.value?.metaTitle ?? appTitle);
|
||||
|
||||
return {
|
||||
logo,
|
||||
global,
|
||||
navbar,
|
||||
footer,
|
||||
seo,
|
||||
title,
|
||||
};
|
||||
};
|
63
app/composables/useSitemap.ts
Normal file
63
app/composables/useSitemap.ts
Normal file
|
@ -0,0 +1,63 @@
|
|||
import type Page from "~~/types/collection/page";
|
||||
import type { ComponentTypes } from "~~/types/component/baseComponent";
|
||||
|
||||
export const useSitemap = () => {
|
||||
const { navbar, footer } = useGlobal();
|
||||
const pages = useState<Page[]>("sitemap_pages");
|
||||
|
||||
const sitemap = ref<sitemap>([]);
|
||||
|
||||
for (const element of navbar.value?.navbar_items ?? []) {
|
||||
if (!element.default_active_child) {
|
||||
sitemap.value.push({
|
||||
path: element.URL.startsWith("/") ? element.URL : `/${element.URL}`,
|
||||
origin: "navbar",
|
||||
document: element?.page?.documentId,
|
||||
hasCollection: element.page.content.filter((c: ComponentTypes) => c.__component == "shared.list").length != 0,
|
||||
});
|
||||
}
|
||||
for (const subelement of element.navbar_sub_items) {
|
||||
let url = `${element.URL}/${subelement.URL}`;
|
||||
sitemap.value.push({
|
||||
path: url.startsWith("/") ? url : `/${url}`,
|
||||
origin: "navbar",
|
||||
document: subelement?.page?.documentId,
|
||||
hasCollection:
|
||||
subelement?.page?.content.filter((c: ComponentTypes) => c.__component == "shared.list").length != 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const element of pages.value) {
|
||||
let url = element.slug.replaceAll("~", "/");
|
||||
if (!sitemap.value.find((a) => a.path == url)) {
|
||||
sitemap.value.push({
|
||||
path: url.startsWith("/") ? url : `/${url}`,
|
||||
origin: "page",
|
||||
document: element.documentId,
|
||||
hasCollection: element.content.filter((c: ComponentTypes) => c.__component == "shared.list").length != 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const element of footer.value?.links ?? []) {
|
||||
let url = element.URL.startsWith("/") ? element.URL : `/${element.URL}`;
|
||||
if (!sitemap.value.find((a) => a.path == url) && !element.URL.startsWith("http")) {
|
||||
sitemap.value.push({
|
||||
path: url,
|
||||
origin: "footer",
|
||||
document: undefined,
|
||||
hasCollection: undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return sitemap;
|
||||
};
|
||||
|
||||
type sitemap = Array<{
|
||||
path: string;
|
||||
origin: string;
|
||||
document?: string;
|
||||
hasCollection?: boolean;
|
||||
}>;
|
Loading…
Add table
Add a link
Reference in a new issue