diff --git a/astro/src/pages/sitemap/albums-[page].xml.ts b/astro/src/pages/sitemap/albums-[page].xml.ts new file mode 100644 index 0000000..94fe0f1 --- /dev/null +++ b/astro/src/pages/sitemap/albums-[page].xml.ts @@ -0,0 +1,52 @@ +import { getSettings } from "@/content/settings/settings"; +import type { APIRoute } from "astro"; +import minifyXML from "minify-xml"; + +export const GET = (async ({ params }) => { + const settings = await getSettings(); + + const currentPage = params.page; + + let pages: SitemapPage[] = [ + { + url: "/", + lastModified: new Date() + } + ]; + + let sitemapContent = ` + + + ${pages.map((page) => ` + + ${settings.website.domainName}${page.url} + ${page.lastModified.toISOString()} + + `).join('')} + + `; + + return new Response(minifyXML(sitemapContent), { + status: 200, + statusText: "OK", + headers: { + "Content-Type": "application/xml" + } + }); +}) satisfies APIRoute; + +export async function getStaticPaths() { + const settings = await getSettings(); + + const albumCount = 250; + const perPage = settings.sitemap.perPage; + const pages = Math.ceil(albumCount / perPage); + + let items: any[] = []; + + for (let i = 0; i < pages; i++) { + items.push({ params: { page: (i + 1) } }); + } + + return items; +} diff --git a/astro/src/pages/sitemap/albums.xml.ts b/astro/src/pages/sitemap/albums.xml.ts new file mode 100644 index 0000000..c4de286 --- /dev/null +++ b/astro/src/pages/sitemap/albums.xml.ts @@ -0,0 +1,40 @@ +import { getSettings } from "@/content/settings/settings"; +import type { APIRoute } from "astro"; +import minifyXML from "minify-xml"; + +export const GET = (async () => { + const settings = await getSettings(); + + const albumCount = 250; + const perPage = settings.sitemap.perPage; + const pages = Math.ceil(albumCount / perPage); + + let sitemaps: SitemapIndex[] = []; + + for (let i = 0; i < pages; i++) { + sitemaps.push({ + url: `/sitemap/albums-${i + 1}.xml`, + lastModified: new Date() + }); + } + + let sitemapContent = ` + + + ${sitemaps.map((item) => ` + + ${settings.website.domainName}${item.url} + ${item.lastModified.toISOString()} + + `).join('')} + + `; + + return new Response(minifyXML(sitemapContent), { + status: 200, + statusText: "OK", + headers: { + "Content-Type": "application/xml" + } + }); +}) satisfies APIRoute; diff --git a/astro/src/pages/sitemap/blogs.xml.ts b/astro/src/pages/sitemap/blogs.xml.ts index 97f7369..2f782fe 100644 --- a/astro/src/pages/sitemap/blogs.xml.ts +++ b/astro/src/pages/sitemap/blogs.xml.ts @@ -25,8 +25,6 @@ export const GET = (async () => { }); } - console.log(pages, sitemaps); - let sitemapContent = ` diff --git a/astro/src/pages/sitemap/pages-[page].xml.ts b/astro/src/pages/sitemap/pages-[page].xml.ts new file mode 100644 index 0000000..cbe163a --- /dev/null +++ b/astro/src/pages/sitemap/pages-[page].xml.ts @@ -0,0 +1,52 @@ +import { getSettings } from "@/content/settings/settings"; +import type { APIRoute } from "astro"; +import minifyXML from "minify-xml"; + +export const GET = (async ({ params }) => { + const settings = await getSettings(); + + const currentPage = params.page; + + let pages: SitemapPage[] = [ + { + url: "/", + lastModified: new Date() + } + ]; + + let sitemapContent = ` + + + ${pages.map((page) => ` + + ${settings.website.domainName}${page.url} + ${page.lastModified.toISOString()} + + `).join('')} + + `; + + return new Response(minifyXML(sitemapContent), { + status: 200, + statusText: "OK", + headers: { + "Content-Type": "application/xml" + } + }); +}) satisfies APIRoute; + +export async function getStaticPaths() { + const settings = await getSettings(); + + const pageCount = 250; + const perPage = settings.sitemap.perPage; + const pages = Math.ceil(pageCount / perPage); + + let items: any[] = []; + + for (let i = 0; i < pages; i++) { + items.push({ params: { page: (i + 1) } }); + } + + return items; +} diff --git a/astro/src/pages/sitemap/pages.xml.ts b/astro/src/pages/sitemap/pages.xml.ts new file mode 100644 index 0000000..e58fe0a --- /dev/null +++ b/astro/src/pages/sitemap/pages.xml.ts @@ -0,0 +1,40 @@ +import { getSettings } from "@/content/settings/settings"; +import type { APIRoute } from "astro"; +import minifyXML from "minify-xml"; + +export const GET = (async () => { + const settings = await getSettings(); + + const pageCount = 250; + const perPage = settings.sitemap.perPage; + const pages = Math.ceil(pageCount / perPage); + + let sitemaps: SitemapIndex[] = []; + + for (let i = 0; i < pages; i++) { + sitemaps.push({ + url: `/sitemap/pages-${i + 1}.xml`, + lastModified: new Date() + }); + } + + let sitemapContent = ` + + + ${sitemaps.map((item) => ` + + ${settings.website.domainName}${item.url} + ${item.lastModified.toISOString()} + + `).join('')} + + `; + + return new Response(minifyXML(sitemapContent), { + status: 200, + statusText: "OK", + headers: { + "Content-Type": "application/xml" + } + }); +}) satisfies APIRoute; diff --git a/astro/src/pages/sitemap/projects-[page].xml.ts b/astro/src/pages/sitemap/projects-[page].xml.ts new file mode 100644 index 0000000..55db4f6 --- /dev/null +++ b/astro/src/pages/sitemap/projects-[page].xml.ts @@ -0,0 +1,59 @@ +import { getSettings } from "@/content/settings/settings"; +import type { APIRoute } from "astro"; +import minifyXML from "minify-xml"; + +export const GET = (async ({ params }) => { + const settings = await getSettings(); + + if (!settings.project.enabled) { + return new Response(null, { + status: 204, + statusText: "Not Found" + }); + } + + const currentPage = params.page; + + let pages: SitemapPage[] = [ + { + url: "/", + lastModified: new Date() + } + ]; + + let sitemapContent = ` + + + ${pages.map((page) => ` + + ${settings.website.domainName}${page.url} + ${page.lastModified.toISOString()} + + `).join('')} + + `; + + return new Response(minifyXML(sitemapContent), { + status: 200, + statusText: "OK", + headers: { + "Content-Type": "application/xml" + } + }); +}) satisfies APIRoute; + +export async function getStaticPaths() { + const settings = await getSettings(); + + const projectCount = 250; + const perPage = settings.sitemap.perPage; + const pages = Math.ceil(projectCount / perPage); + + let items: any[] = []; + + for (let i = 0; i < pages; i++) { + items.push({ params: { page: (i + 1) } }); + } + + return items; +} diff --git a/astro/src/pages/sitemap/projects.xml.ts b/astro/src/pages/sitemap/projects.xml.ts new file mode 100644 index 0000000..78237b3 --- /dev/null +++ b/astro/src/pages/sitemap/projects.xml.ts @@ -0,0 +1,47 @@ +import { getSettings } from "@/content/settings/settings"; +import type { APIRoute } from "astro"; +import minifyXML from "minify-xml"; + +export const GET = (async () => { + const settings = await getSettings(); + + if (!settings.blog.enabled) { + return new Response(null, { + status: 204, + statusText: "Not Found" + }); + } + + const projectCount = 250; + const perPage = settings.sitemap.perPage; + const pages = Math.ceil(projectCount / perPage); + + let sitemaps: SitemapIndex[] = []; + + for (let i = 0; i < pages; i++) { + sitemaps.push({ + url: `/sitemap/projects-${i + 1}.xml`, + lastModified: new Date() + }); + } + + let sitemapContent = ` + + + ${sitemaps.map((item) => ` + + ${settings.website.domainName}${item.url} + ${item.lastModified.toISOString()} + + `).join('')} + + `; + + return new Response(minifyXML(sitemapContent), { + status: 200, + statusText: "OK", + headers: { + "Content-Type": "application/xml" + } + }); +}) satisfies APIRoute;