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_old/
# env
.env*

View file

@ -31,7 +31,8 @@ async function readSubdir(subdir: string): Promise<dirData[]> {
}
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, {
withFileTypes: true,
});

View file

@ -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(
/@@((?<module>([A-Z]\w*\.)*)(?<type>([A-Z]\w*))\.?)?((?<member>[a-z]\w*)((?<function>\(\))|(?<signal>\(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(
/@@((?<module>([A-Z]\w*\.)*)(?<type>([A-Z]\w*))\.?)?((?<member>[a-z]\w*)((?<function>\(\))|(?<signal>\(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,
],
};