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
2024-12-19 13:15:42 +02:00
committed by GitHub
parent 3f4d574748
commit 16ae192456
41 changed files with 424 additions and 62 deletions
@@ -1,5 +1,5 @@
import path from "path"
import { getFileSlugSyncUtil } from "./get-file-slug.js"
import { getFileSlugSync } from "../../../docs-utils/dist/index.js"
export type FixLinkOptions = {
currentPageFilePath: string
@@ -20,7 +20,7 @@ export function fixLinkUtil({
fullLinkedFilePath = fullLinkedFilePath.replace(hash, "")
// get absolute path of the URL
const linkedFilePath = fullLinkedFilePath.replace(basePath, "")
const linkedFileSlug = getFileSlugSyncUtil(fullLinkedFilePath)
const linkedFileSlug = getFileSlugSync(fullLinkedFilePath)
const newLink =
linkedFileSlug ||
@@ -1,23 +0,0 @@
import { getFrontMatterUtil } from "./get-front-matter.js"
import { matter } from "vfile-matter"
import { readSync } from "to-vfile"
import { FrontMatter } from "../types/index.js"
export async function getFileSlugUtil(
filePath: string
): Promise<string | undefined> {
const fileFrontmatter = await getFrontMatterUtil(filePath)
if (fileFrontmatter.slug) {
// add to slugs array
return fileFrontmatter.slug
}
}
export function getFileSlugSyncUtil(filePath: string): string | undefined {
const content = readSync(filePath)
matter(content)
return ((content.data.matter as FrontMatter).slug as string) || undefined
}
@@ -1,24 +0,0 @@
import remarkFrontmatter from "remark-frontmatter"
import remarkParse from "remark-parse"
import remarkStringify from "remark-stringify"
import { unified } from "unified"
import { read } from "to-vfile"
import { matter } from "vfile-matter"
import { FrontMatter } from "../types/index.js"
export async function getFrontMatterUtil(
filePath: string
): Promise<FrontMatter> {
return (
await unified()
.use(remarkParse)
.use(remarkStringify)
.use(remarkFrontmatter, ["yaml"])
.use(() => {
return (tree, file) => {
matter(file)
}
})
.process(await read(filePath))
).data.matter as FrontMatter
}