docs: fix sitemap of ui docs (#11928)
This commit is contained in:
14
www/apps/ui/src/app/sitemap.ts
Normal file
14
www/apps/ui/src/app/sitemap.ts
Normal file
@@ -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)}`,
|
||||
}))
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<sitemap>
|
||||
<loc>https://docs.medusajs.com/ui/assets/sitemap.xml</loc>
|
||||
</sitemap>
|
||||
<sitemap>
|
||||
<loc>https://docs.medusajs.com/sitemap-docs.xml</loc>
|
||||
</sitemap>
|
||||
</sitemapindex>
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user