mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
🛠️ Update copyBtn styles for rehypeCopyBtn plugin + create generateToC() + return createdAt, updatedAt & tableOfContents
This commit is contained in:
+19
-5
@@ -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,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user