diff --git a/components/base/ListImageItem.vue b/components/base/ListImageItem.vue index 4a40a1d..fc4ac3b 100644 --- a/components/base/ListImageItem.vue +++ b/components/base/ListImageItem.vue @@ -13,7 +13,7 @@ />

{{ itemIndex }}. diff --git a/components/base/ListItem.vue b/components/base/ListItem.vue index 2be7a84..3746e9e 100644 --- a/components/base/ListItem.vue +++ b/components/base/ListItem.vue @@ -4,7 +4,7 @@ :class="allowNavigation ? '' : 'pointer-events-none'" :to="`${urlOverwrite ?? $route.path}/${data?.slug}`" > -

+

{{ itemIndex }}.

diff --git a/composables/calculateSitemap.ts b/composables/calculateSitemap.ts new file mode 100644 index 0000000..dbd7f51 --- /dev/null +++ b/composables/calculateSitemap.ts @@ -0,0 +1,71 @@ +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(); + + const nuxtApp = useNuxtApp(); + const { navbar, footer } = await nuxtApp.runWithContext(() => provideGlobal()); + const { data: page_res } = await nuxtApp.runWithContext(() => + useAsyncData("sitemap_pages", () => + find("pages", { + filters: { + ref_only_access: false, + }, + }) + ) + ); + const pages = page_res.value?.data ?? []; + + const accessableURLs: Array<{ path: string; origin: string; document?: string; hasCollection?: boolean }> = []; + + for (const element of navbar?.navbar_items ?? []) { + if (!element.default_active_child) { + accessableURLs.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}`; + accessableURLs.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) { + let url = element.slug.replaceAll("~", "/"); + if (!accessableURLs.find((a) => a.path == url)) { + accessableURLs.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?.links ?? []) { + let url = element.URL.startsWith("/") ? element.URL : `/${element.URL}`; + if (!accessableURLs.find((a) => a.path == url) && !element.URL.startsWith("http")) { + accessableURLs.push({ + path: url, + origin: "footer", + document: undefined, + hasCollection: undefined, + }); + } + } + + return accessableURLs; +} diff --git a/pages/[...slug].vue b/pages/[...slug].vue index ea7b66c..da75b80 100644 --- a/pages/[...slug].vue +++ b/pages/[...slug].vue @@ -1,5 +1,4 @@