change: loading performance
This commit is contained in:
parent
7c8be0ccb9
commit
716b5535ae
14 changed files with 129 additions and 98 deletions
|
@ -1,11 +0,0 @@
|
|||
import provideGlobal from "./provideGlobal";
|
||||
|
||||
export default async function () {
|
||||
const runtimeConfig = useRuntimeConfig();
|
||||
const appTitle = runtimeConfig.public.app.title;
|
||||
|
||||
const { SEO } = await provideGlobal();
|
||||
const { metaTitle } = SEO ?? {};
|
||||
|
||||
return metaTitle ?? appTitle;
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
import type Global from "../types/single/global";
|
||||
|
||||
export default async function () {
|
||||
const { findOne } = useStrapi();
|
||||
const { data: global } = await useAsyncData("global", () => findOne<Global>("global"));
|
||||
const { logo, navbar, footer, SEO } = global.value?.data ?? {};
|
||||
|
||||
return { logo, navbar, footer, SEO };
|
||||
}
|
26
composables/useGlobal.ts
Normal file
26
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,
|
||||
};
|
||||
};
|
|
@ -1,30 +1,15 @@
|
|||
import type Article from "../types/collection/article";
|
||||
import type Page from "../types/collection/page";
|
||||
import type { ComponentTypes } from "../types/component/baseComponent";
|
||||
import type SharedList from "../types/component/shared/list";
|
||||
import type Global from "../types/single/global";
|
||||
|
||||
export default async function () {
|
||||
const { find } = useStrapi();
|
||||
export const useSitemap = () => {
|
||||
const { navbar, footer } = useGlobal();
|
||||
const pages = useState<Page[]>("sitemap_pages");
|
||||
|
||||
const nuxtApp = useNuxtApp();
|
||||
const { navbar, footer } = await nuxtApp.runWithContext(() => provideGlobal());
|
||||
const { data: page_res } = await nuxtApp.runWithContext(() =>
|
||||
useAsyncData("sitemap_pages", () =>
|
||||
find<Page>("pages", {
|
||||
filters: {
|
||||
ref_only_access: false,
|
||||
},
|
||||
})
|
||||
)
|
||||
);
|
||||
const pages = page_res.value?.data ?? [];
|
||||
const sitemap = ref<sitemap>([]);
|
||||
|
||||
const accessableURLs: Array<{ path: string; origin: string; document?: string; hasCollection?: boolean }> = [];
|
||||
|
||||
for (const element of navbar?.navbar_items ?? []) {
|
||||
for (const element of navbar.value?.navbar_items ?? []) {
|
||||
if (!element.default_active_child) {
|
||||
accessableURLs.push({
|
||||
sitemap.value.push({
|
||||
path: element.URL.startsWith("/") ? element.URL : `/${element.URL}`,
|
||||
origin: "navbar",
|
||||
document: element?.page?.documentId,
|
||||
|
@ -33,7 +18,7 @@ export default async function () {
|
|||
}
|
||||
for (const subelement of element.navbar_sub_items) {
|
||||
let url = `${element.URL}/${subelement.URL}`;
|
||||
accessableURLs.push({
|
||||
sitemap.value.push({
|
||||
path: url.startsWith("/") ? url : `/${url}`,
|
||||
origin: "navbar",
|
||||
document: subelement?.page?.documentId,
|
||||
|
@ -43,10 +28,10 @@ export default async function () {
|
|||
}
|
||||
}
|
||||
|
||||
for (const element of pages) {
|
||||
for (const element of pages.value) {
|
||||
let url = element.slug.replaceAll("~", "/");
|
||||
if (!accessableURLs.find((a) => a.path == url)) {
|
||||
accessableURLs.push({
|
||||
if (!sitemap.value.find((a) => a.path == url)) {
|
||||
sitemap.value.push({
|
||||
path: url.startsWith("/") ? url : `/${url}`,
|
||||
origin: "page",
|
||||
document: element.documentId,
|
||||
|
@ -55,10 +40,10 @@ export default async function () {
|
|||
}
|
||||
}
|
||||
|
||||
for (const element of footer?.links ?? []) {
|
||||
for (const element of footer.value?.links ?? []) {
|
||||
let url = element.URL.startsWith("/") ? element.URL : `/${element.URL}`;
|
||||
if (!accessableURLs.find((a) => a.path == url) && !element.URL.startsWith("http")) {
|
||||
accessableURLs.push({
|
||||
if (!sitemap.value.find((a) => a.path == url) && !element.URL.startsWith("http")) {
|
||||
sitemap.value.push({
|
||||
path: url,
|
||||
origin: "footer",
|
||||
document: undefined,
|
||||
|
@ -67,5 +52,12 @@ export default async function () {
|
|||
}
|
||||
}
|
||||
|
||||
return accessableURLs;
|
||||
}
|
||||
return sitemap;
|
||||
};
|
||||
|
||||
type sitemap = Array<{
|
||||
path: string;
|
||||
origin: string;
|
||||
document?: string;
|
||||
hasCollection?: boolean;
|
||||
}>;
|
Loading…
Add table
Add a link
Reference in a new issue