refactor #5

Merged
GauthierWebDev merged 8 commits from refactor into main 2025-04-18 09:55:16 +00:00
2 changed files with 11 additions and 22 deletions
Showing only changes of commit a02916d76a - Show all commits

View File

@ -1,21 +1,11 @@
// Workaround about undefined import only in production build
import type { RenderableTreeNode } from "@markdoc/markdoc"; import type { RenderableTreeNode } from "@markdoc/markdoc";
import type { ReactNode } from "react";
export class Tag<N extends string = string, A extends Record<string, any> = Record<string, any>> { import { Tag as MarkdocTag } from "@markdoc/markdoc";
readonly $$mdtype = "Tag" as const;
static isTag = (tag: any): tag is Tag => { export class Tag extends MarkdocTag {
return !!(tag?.$$mdtype === "Tag"); constructor(name: string | ReactNode, attributes: Record<string, any>, children: RenderableTreeNode[]) {
}; // Workaround for TypeScript's type system
super(name as unknown as string, attributes, children);
name: N;
attributes: A;
children: RenderableTreeNode[];
constructor(name = "div" as N, attributes = {} as A, children: RenderableTreeNode[] = []) {
this.name = name;
this.attributes = attributes;
this.children = children;
} }
} }

View File

@ -1,13 +1,12 @@
import type { Config, Node } from "@markdoc/markdoc"; import type { Config, Node } from "@markdoc/markdoc";
import { slugifyWithCounter } from "@sindresorhus/slugify"; import { slugifyWithCounter } from "@sindresorhus/slugify";
import { nodes as defaultNodes } from "@markdoc/markdoc";
import { DocsLayout } from "@syntax/DocsLayout"; import { DocsLayout } from "@syntax/DocsLayout";
import Markdoc from "@markdoc/markdoc";
import { Fence } from "@syntax/Fence";
import yaml from "js-yaml";
import { Link } from "@/components/common/Link"; import { Link } from "@/components/common/Link";
import { Fence } from "@syntax/Fence";
const { nodes: defaultNodes, Tag } = Markdoc; import { Tag } from "./Tag";
import yaml from "js-yaml";
let documentSlugifyMap = new Map(); let documentSlugifyMap = new Map();
@ -19,7 +18,7 @@ const nodes = {
documentSlugifyMap.set(config, slugifyWithCounter()); documentSlugifyMap.set(config, slugifyWithCounter());
return new Tag( return new Tag(
this.render, this.render as unknown as string,
{ {
frontmatter: yaml.load(node.attributes.frontmatter), frontmatter: yaml.load(node.attributes.frontmatter),
estimatedReadingTime: config?.variables?.estimatedReadingTime, estimatedReadingTime: config?.variables?.estimatedReadingTime,