chore: reorganize docs apps (#7228)

* reorganize docs apps

* add README

* fix directory

* add condition for old docs
This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-05-03 17:36:38 +03:00
1 parent 224ebb2154
commit 4fe28f5a95
6187 files changed
+601447 -598226

No files matched your search

@@ -0,0 +1,3 @@
export function basePathUrl(path = "") {
return `${process.env.NEXT_PUBLIC_BASE_PATH}${path}`
}
@@ -0,0 +1,12 @@
const HEADING_REGEX = /# (?<title>.*)/
/**
*
* @param {string} content - The content to search
* @returns {string | undefined}
*/
export default function findPageHeading(content) {
const headingMatch = HEADING_REGEX.exec(content)
return headingMatch?.groups?.title
}
+60
View File
@@ -0,0 +1,60 @@
import { statSync, readdirSync } from "fs"
import path from "path"
import { getFileSlugUtil } from "remark-rehype-plugins"
const monoRepoPath = path.resolve("..", "..", "..")
/**
*
* @param {string} dir - The directory to search in
* @returns {Promise<{ origSlug: string; newSlug: string }[]>}
*/
export default async function getSlugs(options = {}) {
let { dir, basePath = path.resolve("app"), baseSlug = basePath } = options
if (!dir) {
dir = basePath
}
/**
* @type {{ origSlug: string; newSlug: string }[]}
*/
const slugs = []
// ignore general reference files
if (dir.endsWith("/references/medusa") || dir.endsWith("/references/types")) {
return slugs
}
const files = readdirSync(dir)
for (const file of files) {
const filePath = path.join(dir, file)
const fileBasename = path.basename(file)
if (fileBasename !== "page.mdx") {
const fileStat = statSync(filePath)
if (fileStat.isDirectory()) {
slugs.push(
...(await getSlugs({
dir: filePath,
basePath,
baseSlug,
}))
)
}
continue
}
const newSlug = await getFileSlugUtil(filePath)
if (newSlug) {
slugs.push({
origSlug: filePath
.replace(baseSlug, "")
.replace(fileBasename, "")
.replace(/\/$/, ""),
newSlug,
filePath: filePath.replace(monoRepoPath, ""),
})
}
}
return slugs
}
@@ -0,0 +1,18 @@
/** @type {Partial<import("../types").SidebarItemType>} */
const commonOptions = {
loaded: true,
isPathHref: true,
}
/**
*
* @param {import("types").SidebarItemType[]} sidebar
* @returns {import("types").SidebarItemType[]}
*/
export function sidebarAttachHrefCommonOptions(sidebar) {
return sidebar.map((item) => ({
...commonOptions,
...item,
children: sidebarAttachHrefCommonOptions(item.children || []),
}))
}