From 4a4d867ab9af7fc157d39acf9185006d5618e17e Mon Sep 17 00:00:00 2001 From: GauthierWebDev Date: Fri, 18 Apr 2025 17:50:32 +0200 Subject: [PATCH] feat: Update sitemap with additional URLs and sitemap logic --- app/public/sitemap.xml | 2 +- app/services/Sitemap.ts | 52 +++++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/app/public/sitemap.xml b/app/public/sitemap.xml index edf58cf..085453d 100644 --- a/app/public/sitemap.xml +++ b/app/public/sitemap.xml @@ -1 +1 @@ - \ No newline at end of file +http://localhost:5500/2025-04-18T15:49:26.620Z1.0http://localhost:5500/certifications2025-04-18T15:49:26.620Z0.9http://localhost:5500/docs2025-04-18T15:49:26.620Z0.9http://localhost:5500/docs/communaute/influenceurs2025-04-18T15:49:26.620Z0.7http://localhost:5500/docs/communaute/partages2025-04-18T15:49:26.620Z0.7http://localhost:5500/mentions-legales2025-04-18T15:49:26.620Z0.9http://localhost:5500/politique-de-confidentialite2025-04-18T15:49:26.620Z0.9http://localhost:5500/certifications/dwwm2025-04-18T15:49:26.620Z0.8http://localhost:5500/certifications/dwwm/at12025-04-18T15:49:26.620Z0.7http://localhost:5500/certifications/dwwm/at22025-04-18T15:49:26.620Z0.7http://localhost:5500/docs/react2025-04-18T15:49:26.620Z0.8http://localhost:5500/docs/merise2025-04-18T15:49:26.620Z0.8 \ No newline at end of file diff --git a/app/services/Sitemap.ts b/app/services/Sitemap.ts index 908424e..e749d6b 100644 --- a/app/services/Sitemap.ts +++ b/app/services/Sitemap.ts @@ -53,7 +53,13 @@ class Sitemap { this.sitemap += ``; } - private addSitemapElement(url: SitemapElement): void {} + private addSitemapElement(url: SitemapElement): void { + this.sitemap += ``; + this.sitemap += `${url.location}`; + this.sitemap += `${url.lastmod || this.lastModified}`; + this.sitemap += `${url.priority}`; + this.sitemap += ``; + } private buildSitemap(): void { this.prependSitemap(); @@ -67,34 +73,40 @@ class Sitemap { private loadPriority(href: string): string { const isRootUrl = ["/", ""].includes(href); - const isMainUrl = ["/docs", "/certifications", "/politique-de-confidentialite", "/mentions-legales"].includes(href); if (isRootUrl) return "1.0"; - if (isMainUrl) return "0.9"; - return "0.8"; + const countOfSlashes = (href.match(/\//g) || []).length; + return (1 - countOfSlashes * 0.1).toFixed(1); } private loadLastModified(href: string): string {} private loadFile(href: string) {} - private loadUrls(): void { - this.urls = navigation.flatMap((item) => { - return item.links - .map((link) => { - const file = this.loadFile(link.href); - if (!file) { - console.warn(`File not found for URL: ${link.href}`); - return null; - } + private loadSection(sectionLinks: (typeof navigation)[number]["links"]) { + return sectionLinks.map((link) => { + const href = link.href; + const priority = this.loadPriority(href); + const lastmod = this.loadLastModified(href); + const location = `${this.baseUrl}${href}`; - return { - location: `${this.baseUrl}${link.href}`, - lastmod: this.loadLastModified(link.href), - priority: this.loadPriority(link.href), - }; - }) - .filter((url) => url !== null); + return { + location, + lastmod, + priority, + }; + }); + } + + private loadUrls(): void { + this.urls = navigation.flatMap((section) => { + return Array.from( + new Set( + this.loadSection(section.links) + .filter((url) => url !== null) + .sort((a, b) => a.location.localeCompare(b.location)), + ), + ); }); console.log("Loaded URLs:", this.urls);