docs: add tags package to generate tags (#10666)
* initial changes * finalize implementation * run generator on prep * remove tags package from book * optimization attempt * test transpile * test transpile * rename utils * rename directory * add vercel ignore * add tags to book
This commit is contained in:
1 parent
3f4d574748
commit
16ae192456
41 files changed
+424
-62
No files matched your search
@@ -24,13 +24,15 @@
|
||||
],
|
||||
"scripts": {
|
||||
"build": "yarn clean && tsc",
|
||||
"clean": "rimraf dist"
|
||||
"clean": "rimraf dist",
|
||||
"watch": "tsc --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"remark-rehype-plugins": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.11.20",
|
||||
"docs-utils": "*",
|
||||
"rimraf": "^5.0.5",
|
||||
"tsconfig": "*",
|
||||
"types": "*",
|
||||
|
||||
@@ -2,8 +2,6 @@ export * from "./generate-edited-dates.js"
|
||||
export * from "./generate-sidebar.js"
|
||||
export * from "./retrieve-mdx-pages.js"
|
||||
|
||||
export * from "./utils/find-metadata-title.js"
|
||||
export * from "./utils/find-page-heading.js"
|
||||
export * from "./utils/get-core-flows-ref-sidebar-children.js"
|
||||
export * from "./utils/get-sidebar-item-link.js"
|
||||
export * from "./utils/sidebar-attach-href-common-options.js"
|
||||
@@ -1,6 +1,6 @@
|
||||
import { readdirSync } from "fs"
|
||||
import path from "path"
|
||||
import { getFileSlugSyncUtil } from "remark-rehype-plugins"
|
||||
import { getFileSlugSync } from "../../docs-utils/dist/index.js"
|
||||
|
||||
type Options = {
|
||||
basePath: string
|
||||
@@ -24,7 +24,7 @@ export function retrieveMdxPages({ basePath }: Options): string[] {
|
||||
continue
|
||||
}
|
||||
|
||||
const slug = getFileSlugSyncUtil(filePath)
|
||||
const slug = getFileSlugSync(filePath)
|
||||
|
||||
urls.push(
|
||||
slug ||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
const REGEX = /export const metadata = {[\s\S]*title: `(?<title>.*)`/
|
||||
|
||||
export default function findMetadataTitle(content: string): string | undefined {
|
||||
const headingMatch = REGEX.exec(content)
|
||||
|
||||
return headingMatch?.groups?.title
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
const HEADING_REGEX = /# (?<title>.*)/
|
||||
|
||||
export default function findPageHeading(content: string): string | undefined {
|
||||
const headingMatch = HEADING_REGEX.exec(content)
|
||||
|
||||
return headingMatch?.groups?.title
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
import { getFrontMatterUtil } from "remark-rehype-plugins"
|
||||
import { getFrontMatter, findPageTitle } from "../../../docs-utils/dist/index.js"
|
||||
import { ItemsToAdd, sidebarAttachHrefCommonOptions } from "../index.js"
|
||||
import { readFileSync } from "fs"
|
||||
import findMetadataTitle from "./find-metadata-title.js"
|
||||
import findPageHeading from "./find-page-heading.js"
|
||||
import { InteractiveSidebarItem } from "types"
|
||||
|
||||
export async function getSidebarItemLink({
|
||||
@@ -14,26 +11,18 @@ export async function getSidebarItemLink({
|
||||
basePath: string
|
||||
fileBasename: string
|
||||
}): Promise<ItemsToAdd | undefined> {
|
||||
const frontmatter = await getFrontMatterUtil(filePath)
|
||||
const frontmatter = await getFrontMatter(filePath)
|
||||
if (frontmatter.sidebar_autogenerate_exclude) {
|
||||
return
|
||||
}
|
||||
|
||||
const fileContent = frontmatter.sidebar_label
|
||||
? ""
|
||||
: readFileSync(filePath, "utf-8")
|
||||
|
||||
const newItem = sidebarAttachHrefCommonOptions([
|
||||
{
|
||||
type: "link",
|
||||
path:
|
||||
frontmatter.slug ||
|
||||
filePath.replace(basePath, "").replace(`/${fileBasename}`, ""),
|
||||
title:
|
||||
frontmatter.sidebar_label ||
|
||||
findMetadataTitle(fileContent) ||
|
||||
findPageHeading(fileContent) ||
|
||||
"",
|
||||
title: frontmatter.sidebar_label || findPageTitle(filePath) || "",
|
||||
},
|
||||
])[0] as InteractiveSidebarItem
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"tsBuildInfoFile": "./dist/.tsbuildinfo-client",
|
||||
"noEmit": false,
|
||||
"lib": ["es2022"],
|
||||
"target": "es2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"declaration": true,
|
||||
|
||||
Reference in new issue
Block a user