diff --git a/www/apps/ui/src/app/sitemap.ts b/www/apps/ui/src/app/sitemap.ts new file mode 100644 index 0000000000..94d4be150b --- /dev/null +++ b/www/apps/ui/src/app/sitemap.ts @@ -0,0 +1,14 @@ +import { retrieveMdxPages } from "build-scripts" +import type { MetadataRoute } from "next" +import path from "path" +import { siteConfig } from "../config/site" +import { basePathUrl } from "../lib/base-path-url" + +export default function sitemap(): MetadataRoute.Sitemap { + return retrieveMdxPages({ + basePath: path.resolve("src", "content", "docs"), + testFileName: false, + }).map((filePath) => ({ + url: `${siteConfig.baseUrl}${basePathUrl(filePath)}`, + })) +} diff --git a/www/apps/ui/src/app/sitemap.xml b/www/apps/ui/src/app/sitemap.xml deleted file mode 100644 index 3f887be030..0000000000 --- a/www/apps/ui/src/app/sitemap.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - https://docs.medusajs.com/ui/assets/sitemap.xml - - - https://docs.medusajs.com/sitemap-docs.xml - - \ No newline at end of file diff --git a/www/packages/build-scripts/src/retrieve-mdx-pages.ts b/www/packages/build-scripts/src/retrieve-mdx-pages.ts index 892cc44c44..6fa4b167e4 100644 --- a/www/packages/build-scripts/src/retrieve-mdx-pages.ts +++ b/www/packages/build-scripts/src/retrieve-mdx-pages.ts @@ -4,9 +4,13 @@ import { getFileSlugSync } from "docs-utils" type Options = { basePath: string + testFileName?: boolean } -export function retrieveMdxPages({ basePath }: Options): string[] { +export function retrieveMdxPages({ + basePath, + testFileName = true, +}: Options): string[] { function retrieveMdxFilesInPath(dir: string): string[] { const urls = [] const files = readdirSync(dir, { @@ -20,19 +24,26 @@ export function retrieveMdxPages({ basePath }: Options): string[] { urls.push(...retrieveMdxFilesInPath(filePath)) } continue - } else if (file.name !== "page.mdx") { + } else if ( + (testFileName && file.name !== "page.mdx") || + (!testFileName && !file.name.endsWith(".mdx")) + ) { continue } const slug = getFileSlugSync(filePath) - urls.push( - slug || - filePath - .replace(basePath, "") - .replace(file.name, "") - .replace(/\/$/, "") - ) + let url = slug || filePath.replace(basePath, "") + + if (testFileName || file.name === "index.mdx") { + url = url.replace(file.name, "") + } else { + url = url.replace(".mdx", "") + } + + url = url.replace(/\/$/, "") + + urls.push(url) } return urls