fix: probably links?

This commit is contained in:
Oleksandr 2026-04-05 00:06:00 +03:00
parent 940e9e3f2c
commit b9e53ecdd8
Signed by: Xanazf
GPG key ID: 821EEC32761AC17C
3 changed files with 47 additions and 16 deletions

View file

@ -107,8 +107,9 @@ import magnifierIcon from "@icons/magnifier.svg?raw";
const match = [...excerpt.matchAll(linkRegex)]; const match = [...excerpt.matchAll(linkRegex)];
if (match.length > 0) { if (match.length > 0) {
for (const matching of match) { for (const matching of match) {
const currentVersion = import.meta.url;
const linkObject = getQMLTypeLinkObject(matching[1]); const linkObject = getQMLTypeLinkObject(matching[1]);
const link = getQMLTypeLink("NOVERSION", linkObject); const link = getQMLTypeLink(currentVersion, linkObject);
const icon = linkObject.mtype const icon = linkObject.mtype
? getIconForLink(linkObject.mtype, false) ? getIconForLink(linkObject.mtype, false)
: null; : null;
@ -133,7 +134,8 @@ import magnifierIcon from "@icons/magnifier.svg?raw";
//@ts-expect-error //@ts-expect-error
"@pagefind/default-ui" "@pagefind/default-ui"
); );
const versionMatch = window.location.pathname.match(/^\/docs\/([^/]+)/); const versionMatch =
window.location.pathname.match(/^\/docs\/([^/]+)/);
const activeVersion = versionMatch?.[1]; const activeVersion = versionMatch?.[1];
const search = new PagefindUI({ const search = new PagefindUI({

View file

@ -12,7 +12,7 @@ import type {
} from "@components/navigation/sidebars/types"; } from "@components/navigation/sidebars/types";
import type { QMLTypeLinkObject } from "@_types"; import type { QMLTypeLinkObject } from "@_types";
export function buildHierarchy(headings: ConfigHeading[]) { function buildHierarchy(headings: ConfigHeading[]) {
const toc: ConfigTOC[] = []; const toc: ConfigTOC[] = [];
const parentHeadings = new Map(); const parentHeadings = new Map();
@ -42,7 +42,7 @@ export function buildHierarchy(headings: ConfigHeading[]) {
return toc; return toc;
} }
export function getQMLTypeLinkObject(unparsed: string) { function getQMLTypeLinkObject(unparsed: string) {
const isLocal = unparsed.startsWith("MQS_") ? "local" : false; const isLocal = unparsed.startsWith("MQS_") ? "local" : false;
const isQT = unparsed.startsWith("MQT_") ? "qt" : false; const isQT = unparsed.startsWith("MQT_") ? "qt" : false;
const index = isLocal || isQT || "self"; const index = isLocal || isQT || "self";
@ -96,7 +96,7 @@ export function getQMLTypeLinkObject(unparsed: string) {
return hashMap[index](); return hashMap[index]();
} }
export function getQMLTypeLink( function getQMLTypeLink(
version: string, version: string,
{ type, module, name, mtype, mname }: QMLTypeLinkObject { type, module, name, mtype, mname }: QMLTypeLinkObject
) { ) {
@ -132,7 +132,7 @@ export function getQMLTypeLink(
return hashMap[type as keyof typeof hashMap](); return hashMap[type as keyof typeof hashMap]();
} }
export function getIconForLink(mtype: string, isJsx: boolean) { function getIconForLink(mtype: string, isJsx: boolean) {
const TagIconString: string = `<svg const TagIconString: string = `<svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
width="1em" width="1em"
@ -195,3 +195,10 @@ export function getIconForLink(mtype: string, isJsx: boolean) {
return map[mtype as keyof typeof map](); return map[mtype as keyof typeof map]();
} }
export {
buildHierarchy,
getQMLTypeLinkObject,
getQMLTypeLink,
getIconForLink,
};

View file

@ -3,6 +3,7 @@ import { fromHtml } from "hast-util-from-html";
import type * as Unist from "unist"; import type * as Unist from "unist";
import type * as Html from "hast"; import type * as Html from "hast";
import type * as Md from "mdast"; import type * as Md from "mdast";
import type { VFile } from "vfile";
import type { import type {
AstroMarkdownOptions, AstroMarkdownOptions,
MarkdownProcessor, MarkdownProcessor,
@ -23,7 +24,8 @@ import {
} from "./helpers.ts"; } from "./helpers.ts";
import type { CopyButtonOptions } from "@_types"; import type { CopyButtonOptions } from "@_types";
let currentVersion = "NOVERSION"; // WARNING: VERY IMPORTANT! DO NOT FUCK THIS UP!
const versionMatcher = /v\d+_\d+_\d+/;
const remarkParseAtTypes: RemarkPlugin<[]> = const remarkParseAtTypes: RemarkPlugin<[]> =
() => () =>
@ -74,7 +76,15 @@ const remarkParseAtTypes: RemarkPlugin<[]> =
const rehypeRewriteTypelinks: RehypePlugin<[]> = const rehypeRewriteTypelinks: RehypePlugin<[]> =
() => () =>
(root: Html.Root): Html.Root => { (root: Html.Root, file: VFile): Html.Root => {
const frontmatter = (file.data as any)?.astro?.frontmatter;
const frontmatterVersion = frontmatter?.version;
const pathVersion =
file && file.path && file.path.match(versionMatcher);
const version =
(frontmatter && frontmatterVersion) ||
(pathVersion && pathVersion[0]) ||
null;
visit( visit(
root as Unist.Parent, root as Unist.Parent,
"text", "text",
@ -88,7 +98,7 @@ const rehypeRewriteTypelinks: RehypePlugin<[]> =
const linkObject = getQMLTypeLinkObject(match); const linkObject = getQMLTypeLinkObject(match);
const link = getQMLTypeLink( const link = getQMLTypeLink(
currentVersion, version ?? "",
linkObject linkObject
); );
const icon = const icon =
@ -118,7 +128,15 @@ const rehypeRewriteTypelinks: RehypePlugin<[]> =
const rehypeRewriteVersionedDoclinks: RehypePlugin<[]> = const rehypeRewriteVersionedDoclinks: RehypePlugin<[]> =
() => () =>
(root: Html.Root): Html.Root => { (root: Html.Root, file: VFile): Html.Root => {
const frontmatter = (file.data as any)?.astro?.frontmatter;
const frontmatterVersion = frontmatter?.version;
const pathVersion =
file && file.path && file.path.match(versionMatcher);
const version =
(frontmatter && frontmatterVersion) ||
(pathVersion && pathVersion[0]) ||
null;
visit( visit(
root as Unist.Parent, root as Unist.Parent,
"element", "element",
@ -128,7 +146,7 @@ const rehypeRewriteVersionedDoclinks: RehypePlugin<[]> =
!((properties.href as string) ?? "").startsWith("@docs") !((properties.href as string) ?? "").startsWith("@docs")
) )
return CONTINUE; return CONTINUE;
properties.href = `/docs/${currentVersion}/${(properties.href as string).slice(6)}`; properties.href = `/docs/${version || "master"}/${(properties.href as string).slice(6)}`;
return CONTINUE; return CONTINUE;
} }
); );
@ -138,15 +156,21 @@ const rehypeRewriteVersionedDoclinks: RehypePlugin<[]> =
const shikiRewriteTypelinks: ShikiTransformer = { const shikiRewriteTypelinks: ShikiTransformer = {
name: "rewrite-typelinks", name: "rewrite-typelinks",
postprocess(code, _options) { postprocess(code, options) {
// WARN: need to change the code link identifier to this // WARN: need to change the code link identifier to this
const regExp = /TYPE99(\w+.)99TYPE/g; const regExp = /TYPE99(\w+.)99TYPE/g;
const hasTypelinks = code.search(regExp) !== -1; const hasTypelinks = code.search(regExp) !== -1;
const rawMeta = this.options.meta?.__raw || "";
const version = rawMeta && rawMeta.match(versionMatcher);
const currentVersion = version && version[0];
if (hasTypelinks) { if (hasTypelinks) {
code.replace(regExp, (_full: string, match: string) => { code.replace(regExp, (_full: string, match: string) => {
const linkObject = getQMLTypeLinkObject(match); const linkObject = getQMLTypeLinkObject(match);
const link = getQMLTypeLink(currentVersion, linkObject); const link = getQMLTypeLink(
currentVersion || "",
linkObject
);
return `<a href=${link}>${linkObject.name ?? ""}</a>`; return `<a href=${link}>${linkObject.name ?? ""}</a>`;
}); });
} }
@ -267,14 +291,12 @@ async function getMarkdownProcessor(): Promise<MarkdownProcessor> {
} }
async function processMarkdown( async function processMarkdown(
version: string, _version: string,
markdown: string markdown: string
): Promise<string> { ): Promise<string> {
currentVersion = version;
const r = ( const r = (
await (await getMarkdownProcessor()).render(markdown) await (await getMarkdownProcessor()).render(markdown)
).code; ).code;
currentVersion = "NOVERSION";
return r; return r;
} }