added env handling

This commit is contained in:
Xanazf 2024-10-17 21:54:15 +03:00
parent 349c87a205
commit f402ab01e6
Signed by: Xanazf
GPG key ID: 4E4A5AD1FB748427
3 changed files with 69 additions and 48 deletions

3
.gitignore vendored
View file

@ -25,3 +25,6 @@ pnpm-debug.log*
modules/ modules/
modules_old/ modules_old/
# env
.env*

View file

@ -31,7 +31,8 @@ async function readSubdir(subdir: string): Promise<dirData[]> {
} }
export async function generateTypeData(): Promise<RouteData[]> { export async function generateTypeData(): Promise<RouteData[]> {
const mainDir = path.join(process.cwd(), "modules"); const mainDir = import.meta.env.SECRET_MODULES_PATH;
const subdirs = await fs.readdir(mainDir, { const subdirs = await fs.readdir(mainDir, {
withFileTypes: true, withFileTypes: true,
}); });

View file

@ -23,40 +23,48 @@ import {
const remarkParseAtTypes: RemarkPlugin<[]> = () => { const remarkParseAtTypes: RemarkPlugin<[]> = () => {
return (root: Md.Root): Md.Root => { return (root: Md.Root): Md.Root => {
visit( visit(root as Unist.Parent, (rawNode: Unist.Node) => {
root as Unist.Parent, if (
(rawNode: Unist.Node) => { rawNode.type === "text" ||
if (rawNode.type === "text" || (rawNode.type === "code" && (rawNode as Md.Code).lang === "qml")) { (rawNode.type === "code" &&
const node = rawNode as Md.Literal; (rawNode as Md.Code).lang === "qml")
) {
const node = rawNode as Md.Literal;
node.value = node.value.replace( node.value = node.value.replace(
/@@((?<module>([A-Z]\w*\.)*)(?<type>([A-Z]\w*))\.?)?((?<member>[a-z]\w*)((?<function>\(\))|(?<signal>\(s\)))?)?(?=[$.,;:\s]|$)/g, /@@((?<module>([A-Z]\w*\.)*)(?<type>([A-Z]\w*))\.?)?((?<member>[a-z]\w*)((?<function>\(\))|(?<signal>\(s\)))?)?(?=[$.,;:\s]|$)/g,
(_full, ...args) => { (_full, ...args) => {
type Capture = { type Capture = {
module: string | undefined; module: string | undefined;
type: string | undefined; type: string | undefined;
member: string | undefined; member: string | undefined;
function: string | undefined; function: string | undefined;
signal: string | undefined; signal: string | undefined;
} };
const groups = args.pop() as Capture; const groups = args.pop() as Capture;
if (groups.module) { if (groups.module) {
groups.module = groups.module.substring(0, groups.module.length - 1); groups.module = groups.module.substring(
const isQs = groups.module.startsWith("Quickshell"); 0,
groups.module = `99M${isQs ? "QS" : "QT_qml"}_${groups.module.replace(".", "_")}`; groups.module.length - 1
} else groups.module = ""; // WARNING: rehype parser can't currently handle intra-module links );
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.type = groups.type ? `99N${groups.type}` : "";
groups.member = groups.member ? `99V${groups.member}` : ""; groups.member = groups.member
const type = groups.member ? `99T${groups.function ? "func" : groups.signal ? "signal" : "prop"}` : ""; ? `99V${groups.member}`
return `TYPE${groups.module}${groups.type}${groups.member}${type}99TYPE`; : "";
} const type = groups.member
); ? `99T${groups.function ? "func" : groups.signal ? "signal" : "prop"}`
} : "";
return `TYPE${groups.module}${groups.type}${groups.member}${type}99TYPE`;
}
);
} }
); });
return root; return root;
}; };
}; };
@ -124,29 +132,38 @@ const shikiRewriteTypelinks: ShikiTransformer = {
export const markdownConfig: AstroMarkdownOptions = { export const markdownConfig: AstroMarkdownOptions = {
syntaxHighlight: false, syntaxHighlight: false,
remarkPlugins: [remarkParseAtTypes, [remarkAlert, { legacyTitle: true }]], remarkPlugins: [
remarkParseAtTypes,
[remarkAlert, { legacyTitle: true }],
],
rehypePlugins: [ rehypePlugins: [
[rehypeShiki, { [
themes: { rehypeShiki,
light: "slack-ochin", {
dark: "slack-dark", themes: {
}, light: "slack-ochin",
colorReplacements: { dark: "slack-dark",
"slack-ochin": {
"#357b42": "#989eb9", // comments
"#b1108e": "#224bbb", // fields
}, },
"slack-dark": { colorReplacements: {
"#222222": "#0f111a", // bg "slack-ochin": {
"#6a9955": "#525666", // comments "#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 // FIXME: incompatible types between unified/Plugin and Astro/RehypePlugin
[sectionize as RehypePlugin, { idPropertyName: "id" }], [
sectionize as unknown as RehypePlugin,
{ idPropertyName: "id" },
],
rehypeRewriteTypelinks, rehypeRewriteTypelinks,
], ],
}; };