Skip to content

Commit

Permalink
simplify sitemap logic
Browse files Browse the repository at this point in the history
  • Loading branch information
a-hariti committed Jun 6, 2024
1 parent 37c3215 commit abf6da7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {

function docsToSitemap(docs: {slug: string}[], baseUrl: string): MetadataRoute.Sitemap {
const paths = docs.map(({slug}) => slug);
const appendSlash = (path: string) => (path.endsWith('/') ? path : `${path}/`);
const appendSlash = (path: string) => {
if (path === '' || path.endsWith('/')) {
return path;
}
return path + '/';
};
const toFullUrl = (path: string) => `${appendSlash(baseUrl)}${appendSlash(path)}`;
const toSitemapEntry = (url: string) => ({url});
return ['/', ...paths].map(appendSlash).map(toFullUrl).map(toSitemapEntry);
const toSitemapEntry = (path: string) => ({url: toFullUrl(path)});
return ['', ...paths].map(toSitemapEntry);
}

0 comments on commit abf6da7

Please sign in to comment.