fix: probably links?
This commit is contained in:
parent
940e9e3f2c
commit
b9e53ecdd8
3 changed files with 47 additions and 16 deletions
|
|
@ -107,8 +107,9 @@ import magnifierIcon from "@icons/magnifier.svg?raw";
|
|||
const match = [...excerpt.matchAll(linkRegex)];
|
||||
if (match.length > 0) {
|
||||
for (const matching of match) {
|
||||
const currentVersion = import.meta.url;
|
||||
const linkObject = getQMLTypeLinkObject(matching[1]);
|
||||
const link = getQMLTypeLink("NOVERSION", linkObject);
|
||||
const link = getQMLTypeLink(currentVersion, linkObject);
|
||||
const icon = linkObject.mtype
|
||||
? getIconForLink(linkObject.mtype, false)
|
||||
: null;
|
||||
|
|
@ -133,7 +134,8 @@ import magnifierIcon from "@icons/magnifier.svg?raw";
|
|||
//@ts-expect-error
|
||||
"@pagefind/default-ui"
|
||||
);
|
||||
const versionMatch = window.location.pathname.match(/^\/docs\/([^/]+)/);
|
||||
const versionMatch =
|
||||
window.location.pathname.match(/^\/docs\/([^/]+)/);
|
||||
const activeVersion = versionMatch?.[1];
|
||||
|
||||
const search = new PagefindUI({
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import type {
|
|||
} from "@components/navigation/sidebars/types";
|
||||
import type { QMLTypeLinkObject } from "@_types";
|
||||
|
||||
export function buildHierarchy(headings: ConfigHeading[]) {
|
||||
function buildHierarchy(headings: ConfigHeading[]) {
|
||||
const toc: ConfigTOC[] = [];
|
||||
const parentHeadings = new Map();
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ export function buildHierarchy(headings: ConfigHeading[]) {
|
|||
return toc;
|
||||
}
|
||||
|
||||
export function getQMLTypeLinkObject(unparsed: string) {
|
||||
function getQMLTypeLinkObject(unparsed: string) {
|
||||
const isLocal = unparsed.startsWith("MQS_") ? "local" : false;
|
||||
const isQT = unparsed.startsWith("MQT_") ? "qt" : false;
|
||||
const index = isLocal || isQT || "self";
|
||||
|
|
@ -96,7 +96,7 @@ export function getQMLTypeLinkObject(unparsed: string) {
|
|||
return hashMap[index]();
|
||||
}
|
||||
|
||||
export function getQMLTypeLink(
|
||||
function getQMLTypeLink(
|
||||
version: string,
|
||||
{ type, module, name, mtype, mname }: QMLTypeLinkObject
|
||||
) {
|
||||
|
|
@ -132,7 +132,7 @@ export function getQMLTypeLink(
|
|||
return hashMap[type as keyof typeof hashMap]();
|
||||
}
|
||||
|
||||
export function getIconForLink(mtype: string, isJsx: boolean) {
|
||||
function getIconForLink(mtype: string, isJsx: boolean) {
|
||||
const TagIconString: string = `<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="1em"
|
||||
|
|
@ -195,3 +195,10 @@ export function getIconForLink(mtype: string, isJsx: boolean) {
|
|||
|
||||
return map[mtype as keyof typeof map]();
|
||||
}
|
||||
|
||||
export {
|
||||
buildHierarchy,
|
||||
getQMLTypeLinkObject,
|
||||
getQMLTypeLink,
|
||||
getIconForLink,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { fromHtml } from "hast-util-from-html";
|
|||
import type * as Unist from "unist";
|
||||
import type * as Html from "hast";
|
||||
import type * as Md from "mdast";
|
||||
import type { VFile } from "vfile";
|
||||
import type {
|
||||
AstroMarkdownOptions,
|
||||
MarkdownProcessor,
|
||||
|
|
@ -23,7 +24,8 @@ import {
|
|||
} from "./helpers.ts";
|
||||
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<[]> =
|
||||
() =>
|
||||
|
|
@ -74,7 +76,15 @@ const remarkParseAtTypes: RemarkPlugin<[]> =
|
|||
|
||||
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(
|
||||
root as Unist.Parent,
|
||||
"text",
|
||||
|
|
@ -88,7 +98,7 @@ const rehypeRewriteTypelinks: RehypePlugin<[]> =
|
|||
|
||||
const linkObject = getQMLTypeLinkObject(match);
|
||||
const link = getQMLTypeLink(
|
||||
currentVersion,
|
||||
version ?? "",
|
||||
linkObject
|
||||
);
|
||||
const icon =
|
||||
|
|
@ -118,7 +128,15 @@ const rehypeRewriteTypelinks: 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(
|
||||
root as Unist.Parent,
|
||||
"element",
|
||||
|
|
@ -128,7 +146,7 @@ const rehypeRewriteVersionedDoclinks: RehypePlugin<[]> =
|
|||
!((properties.href as string) ?? "").startsWith("@docs")
|
||||
)
|
||||
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;
|
||||
}
|
||||
);
|
||||
|
|
@ -138,15 +156,21 @@ const rehypeRewriteVersionedDoclinks: RehypePlugin<[]> =
|
|||
|
||||
const shikiRewriteTypelinks: ShikiTransformer = {
|
||||
name: "rewrite-typelinks",
|
||||
postprocess(code, _options) {
|
||||
postprocess(code, options) {
|
||||
// WARN: need to change the code link identifier to this
|
||||
const regExp = /TYPE99(\w+.)99TYPE/g;
|
||||
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) {
|
||||
code.replace(regExp, (_full: string, match: string) => {
|
||||
const linkObject = getQMLTypeLinkObject(match);
|
||||
const link = getQMLTypeLink(currentVersion, linkObject);
|
||||
const link = getQMLTypeLink(
|
||||
currentVersion || "",
|
||||
linkObject
|
||||
);
|
||||
return `<a href=${link}>${linkObject.name ?? ""}</a>`;
|
||||
});
|
||||
}
|
||||
|
|
@ -267,14 +291,12 @@ async function getMarkdownProcessor(): Promise<MarkdownProcessor> {
|
|||
}
|
||||
|
||||
async function processMarkdown(
|
||||
version: string,
|
||||
_version: string,
|
||||
markdown: string
|
||||
): Promise<string> {
|
||||
currentVersion = version;
|
||||
const r = (
|
||||
await (await getMarkdownProcessor()).render(markdown)
|
||||
).code;
|
||||
currentVersion = "NOVERSION";
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue