docs: fix sitemap of ui docs (#11928)
This commit is contained in:
1 parent
4c33586946
commit
a3f4560263
3 files changed
+34
-18
No files matched your search
@@ -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 = {
|
type Options = {
|
||||||
basePath: string
|
basePath: string
|
||||||
|
testFileName?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export function retrieveMdxPages({ basePath }: Options): string[] {
|
export function retrieveMdxPages({
|
||||||
|
basePath,
|
||||||
|
testFileName = true,
|
||||||
|
}: Options): string[] {
|
||||||
function retrieveMdxFilesInPath(dir: string): string[] {
|
function retrieveMdxFilesInPath(dir: string): string[] {
|
||||||
const urls = []
|
const urls = []
|
||||||
const files = readdirSync(dir, {
|
const files = readdirSync(dir, {
|
||||||
@@ -20,19 +24,26 @@ export function retrieveMdxPages({ basePath }: Options): string[] {
|
|||||||
urls.push(...retrieveMdxFilesInPath(filePath))
|
urls.push(...retrieveMdxFilesInPath(filePath))
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
} else if (file.name !== "page.mdx") {
|
} else if (
|
||||||
|
(testFileName && file.name !== "page.mdx") ||
|
||||||
|
(!testFileName && !file.name.endsWith(".mdx"))
|
||||||
|
) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const slug = getFileSlugSync(filePath)
|
const slug = getFileSlugSync(filePath)
|
||||||
|
|
||||||
urls.push(
|
let url = slug || filePath.replace(basePath, "")
|
||||||
slug ||
|
|
||||||
filePath
|
if (testFileName || file.name === "index.mdx") {
|
||||||
.replace(basePath, "")
|
url = url.replace(file.name, "")
|
||||||
.replace(file.name, "")
|
} else {
|
||||||
.replace(/\/$/, "")
|
url = url.replace(".mdx", "")
|
||||||
)
|
}
|
||||||
|
|
||||||
|
url = url.replace(/\/$/, "")
|
||||||
|
|
||||||
|
urls.push(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls
|
return urls
|
||||||
|
|||||||
Reference in new issue
Block a user