Files
medusa-store/www/packages/docs-utils/src/find-title.ts
Shahed Nasser 16ae192456 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
2024-12-19 13:15:42 +02:00

24 lines
653 B
TypeScript

import { readFileSync } from "fs"
const REGEX = /export const metadata = {[\s\S]*title: `(?<title>.*)`/
export function findMetadataTitle(content: string): string | undefined {
const headingMatch = REGEX.exec(content)
return headingMatch?.groups?.title
}
const HEADING_REGEX = /# (?<title>.*)/
export function findPageHeading(content: string): string | undefined {
const headingMatch = HEADING_REGEX.exec(content)
return headingMatch?.groups?.title
}
export function findPageTitle(filePath: string): string | undefined {
const content = readFileSync(filePath, "utf-8")
return findMetadataTitle(content) || findPageHeading(content)
}