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:
Shahed Nasser authored and GitHub committed 2024-12-19 13:15:42 +02:00
1 parent 3f4d574748
commit 16ae192456
41 files changed
+424 -62

No files matched your search

@@ -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