docs: add sitemap to API reference (#11985)
* docs: add sitemap to API reference * remove duplicate sitemap * update sitemap
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
import type { MetadataRoute } from "next"
|
||||||
|
import path from "path"
|
||||||
|
import getUrl from "../utils/get-url"
|
||||||
|
import { findAllPageHeadings, getSectionId } from "docs-utils"
|
||||||
|
import OpenAPIParser from "@readme/openapi-parser"
|
||||||
|
import { OpenAPI } from "types"
|
||||||
|
import { readFile } from "fs/promises"
|
||||||
|
|
||||||
|
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||||
|
const items: MetadataRoute.Sitemap = []
|
||||||
|
|
||||||
|
const markdownPath = path.join(process.cwd(), "markdown")
|
||||||
|
|
||||||
|
for (const area of ["store", "admin"]) {
|
||||||
|
// find and parse static headers from pages
|
||||||
|
const markdownContent = await readFile(
|
||||||
|
path.join(markdownPath, `${area}.mdx`),
|
||||||
|
"utf-8"
|
||||||
|
)
|
||||||
|
|
||||||
|
const headings = findAllPageHeadings({ content: markdownContent, level: 2 })
|
||||||
|
headings.forEach((heading) => {
|
||||||
|
const objectID = getSectionId([heading])
|
||||||
|
const url = getUrl(area, objectID)
|
||||||
|
items.push({
|
||||||
|
url,
|
||||||
|
lastModified: new Date(),
|
||||||
|
changeFrequency: "weekly",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// find and index tag and operations
|
||||||
|
const baseSpecs = (await OpenAPIParser.parse(
|
||||||
|
path.join(process.cwd(), `specs/${area}/openapi.full.yaml`)
|
||||||
|
)) as OpenAPI.ExpandedDocument
|
||||||
|
|
||||||
|
baseSpecs.tags?.map((tag) => {
|
||||||
|
const tagName = getSectionId([tag.name])
|
||||||
|
const url = getUrl(area, tagName)
|
||||||
|
items.push({
|
||||||
|
url,
|
||||||
|
lastModified: new Date(),
|
||||||
|
changeFrequency: "weekly",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const paths = baseSpecs.paths
|
||||||
|
|
||||||
|
Object.values(paths).forEach((path) => {
|
||||||
|
Object.values(path).forEach((op) => {
|
||||||
|
const operation = op as OpenAPI.Operation
|
||||||
|
const tag = operation.tags?.[0]
|
||||||
|
const operationName = getSectionId([tag || "", operation.operationId])
|
||||||
|
const url = getUrl(area, operationName)
|
||||||
|
items.push({
|
||||||
|
url,
|
||||||
|
lastModified: new Date(),
|
||||||
|
changeFrequency: "weekly",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return items
|
||||||
|
}
|
||||||
@@ -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/assets/sitemap.xml</loc>
|
|
||||||
</sitemap>
|
|
||||||
<sitemap>
|
|
||||||
<loc>https://docs.medusajs.com/sitemap-docs.xml</loc>
|
|
||||||
</sitemap>
|
|
||||||
</sitemapindex>
|
|
||||||
Reference in New Issue
Block a user