🛠️ Update copyBtn styles for rehypeCopyBtn plugin + create generateToC() + return createdAt, updatedAt & tableOfContents

This commit is contained in:
pheralb
2025-09-14 19:00:20 +01:00
parent e7bbd32b56
commit 1c11725e01
3 changed files with 69 additions and 15 deletions
+19 -5
View File
@@ -1,16 +1,21 @@
import { z } from "zod";
import path from "node:path";
import fs from "node:fs/promises";
// Content Collections:
import { compileMarkdown } from "@content-collections/markdown";
import { defineCollection, defineConfig } from "@content-collections/core";
// Plugings:
// Plugins:
import rehypeSlug from "rehype-slug";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
import rehypeShiki from "@shikijs/rehype/core";
import { shikiHighlighter, rehypeShikiOptions } from "./src/utils/shiki";
import rehypeAutolinkHeadings from "rehype-autolink-headings";
// Custom Plugins:
import { rehypeCopyBtn } from "./src/markdown/rehypeCopyBtn";
import { getTableOfContents } from "./src/markdown/generateToC";
import { rehypeExternalLinks } from "./src/markdown/rehypeExternalLinks";
import { shikiHighlighter, rehypeShikiOptions } from "./src/utils/shiki";
const docs = defineCollection({
name: "docs",
@@ -22,18 +27,27 @@ const docs = defineCollection({
}),
transform: async (document, context) => {
const highlighter = await shikiHighlighter();
const filePath = path.join(
context.collection.directory,
document._meta.filePath,
);
const { mtimeMs, birthtimeMs } = await fs.stat(filePath);
const html = await compileMarkdown(context, document, {
rehypePlugins: [
rehypeSlug,
rehypeAutolinkHeadings,
[rehypeShiki, highlighter, rehypeShikiOptions],
rehypeExternalLinks,
rehypeSlug,
rehypeAutolinkHeadings,
rehypeCopyBtn,
],
});
const tableOfContents = getTableOfContents(document.content);
return {
...document,
html,
createdAt: new Date(birthtimeMs),
updatedAt: new Date(mtimeMs),
tableOfContents,
};
},
});