From f402ab01e6b8354f64092328fdcf214705789c24 Mon Sep 17 00:00:00 2001 From: Xanazf Date: Thu, 17 Oct 2024 21:54:15 +0300 Subject: [PATCH] added env handling --- .gitignore | 3 + src/config/io/generateTypeData.ts | 3 +- src/config/io/markdown.ts | 111 +++++++++++++++++------------- 3 files changed, 69 insertions(+), 48 deletions(-) diff --git a/.gitignore b/.gitignore index 620904b..551c0e1 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ pnpm-debug.log* modules/ modules_old/ + +# env +.env* diff --git a/src/config/io/generateTypeData.ts b/src/config/io/generateTypeData.ts index ef905bf..a39479f 100644 --- a/src/config/io/generateTypeData.ts +++ b/src/config/io/generateTypeData.ts @@ -31,7 +31,8 @@ async function readSubdir(subdir: string): Promise { } export async function generateTypeData(): Promise { - const mainDir = path.join(process.cwd(), "modules"); + const mainDir = import.meta.env.SECRET_MODULES_PATH; + const subdirs = await fs.readdir(mainDir, { withFileTypes: true, }); diff --git a/src/config/io/markdown.ts b/src/config/io/markdown.ts index 31e0e07..b5a715c 100644 --- a/src/config/io/markdown.ts +++ b/src/config/io/markdown.ts @@ -23,40 +23,48 @@ import { const remarkParseAtTypes: RemarkPlugin<[]> = () => { return (root: Md.Root): Md.Root => { - visit( - root as Unist.Parent, - (rawNode: Unist.Node) => { - if (rawNode.type === "text" || (rawNode.type === "code" && (rawNode as Md.Code).lang === "qml")) { - const node = rawNode as Md.Literal; + visit(root as Unist.Parent, (rawNode: Unist.Node) => { + if ( + rawNode.type === "text" || + (rawNode.type === "code" && + (rawNode as Md.Code).lang === "qml") + ) { + const node = rawNode as Md.Literal; - node.value = node.value.replace( - /@@((?([A-Z]\w*\.)*)(?([A-Z]\w*))\.?)?((?[a-z]\w*)((?\(\))|(?\(s\)))?)?(?=[$.,;:\s]|$)/g, - (_full, ...args) => { - type Capture = { - module: string | undefined; - type: string | undefined; - member: string | undefined; - function: string | undefined; - signal: string | undefined; - } + node.value = node.value.replace( + /@@((?([A-Z]\w*\.)*)(?([A-Z]\w*))\.?)?((?[a-z]\w*)((?\(\))|(?\(s\)))?)?(?=[$.,;:\s]|$)/g, + (_full, ...args) => { + type Capture = { + module: string | undefined; + type: string | undefined; + member: string | undefined; + function: string | undefined; + signal: string | undefined; + }; - const groups = args.pop() as Capture; + const groups = args.pop() as Capture; - if (groups.module) { - groups.module = groups.module.substring(0, groups.module.length - 1); - const isQs = groups.module.startsWith("Quickshell"); - groups.module = `99M${isQs ? "QS" : "QT_qml"}_${groups.module.replace(".", "_")}`; - } else groups.module = ""; // WARNING: rehype parser can't currently handle intra-module links + if (groups.module) { + groups.module = groups.module.substring( + 0, + groups.module.length - 1 + ); + const isQs = groups.module.startsWith("Quickshell"); + groups.module = `99M${isQs ? "QS" : "QT_qml"}_${groups.module.replace(".", "_")}`; + } else groups.module = ""; // WARNING: rehype parser can't currently handle intra-module links - groups.type = groups.type ? `99N${groups.type}` : ""; - groups.member = groups.member ? `99V${groups.member}` : ""; - const type = groups.member ? `99T${groups.function ? "func" : groups.signal ? "signal" : "prop"}` : ""; - return `TYPE${groups.module}${groups.type}${groups.member}${type}99TYPE`; - } - ); - } + groups.type = groups.type ? `99N${groups.type}` : ""; + groups.member = groups.member + ? `99V${groups.member}` + : ""; + const type = groups.member + ? `99T${groups.function ? "func" : groups.signal ? "signal" : "prop"}` + : ""; + return `TYPE${groups.module}${groups.type}${groups.member}${type}99TYPE`; + } + ); } - ); + }); return root; }; }; @@ -124,29 +132,38 @@ const shikiRewriteTypelinks: ShikiTransformer = { export const markdownConfig: AstroMarkdownOptions = { syntaxHighlight: false, - remarkPlugins: [remarkParseAtTypes, [remarkAlert, { legacyTitle: true }]], + remarkPlugins: [ + remarkParseAtTypes, + [remarkAlert, { legacyTitle: true }], + ], rehypePlugins: [ - [rehypeShiki, { - themes: { - light: "slack-ochin", - dark: "slack-dark", - }, - colorReplacements: { - "slack-ochin": { - "#357b42": "#989eb9", // comments - "#b1108e": "#224bbb", // fields + [ + rehypeShiki, + { + themes: { + light: "slack-ochin", + dark: "slack-dark", }, - "slack-dark": { - "#222222": "#0f111a", // bg - "#6a9955": "#525666", // comments + colorReplacements: { + "slack-ochin": { + "#357b42": "#989eb9", // comments + "#b1108e": "#224bbb", // fields + }, + "slack-dark": { + "#222222": "#0f111a", // bg + "#6a9955": "#525666", // comments + }, }, + defaultColor: false, + wrap: true, + transformers: [shikiRewriteTypelinks], }, - defaultColor: false, - wrap: true, - transformers: [shikiRewriteTypelinks], - }], + ], // FIXME: incompatible types between unified/Plugin and Astro/RehypePlugin - [sectionize as RehypePlugin, { idPropertyName: "id" }], + [ + sectionize as unknown as RehypePlugin, + { idPropertyName: "id" }, + ], rehypeRewriteTypelinks, ], };