From e72170a4bc90ad4e2f2b24972448018720e56bdd Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sat, 8 Jul 2023 01:34:12 +0100 Subject: [PATCH] fix: build errors --- src/markdown/remark-callout.ts | 2 +- src/markdown/remark-mermaid.ts | 2 +- src/markdown/remark-pangu.ts | 2 +- src/markdown/remark-youtube.ts | 87 +++++++++++++++++----------------- 4 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/markdown/remark-callout.ts b/src/markdown/remark-callout.ts index 59ca963b..82d9d5d0 100644 --- a/src/markdown/remark-callout.ts +++ b/src/markdown/remark-callout.ts @@ -4,7 +4,7 @@ import { visit } from "unist-util-visit" const CALLOUT_RE = /^(TIP|WARN|SUCCESS|DANGER):(\n|$)/ -export const remarkCallout: Plugin, Root> = () => (tree) => { +export const remarkCallout: Plugin, Root> = () => (tree: Root) => { visit(tree, { type: "blockquote" }, (node, index, parent) => { if (node.type !== "blockquote") return diff --git a/src/markdown/remark-mermaid.ts b/src/markdown/remark-mermaid.ts index 340a1665..7c17284f 100644 --- a/src/markdown/remark-mermaid.ts +++ b/src/markdown/remark-mermaid.ts @@ -2,7 +2,7 @@ import { Root } from "remark-gfm" import { Plugin } from "unified" import { visit } from "unist-util-visit" -export const remarkMermaid: Plugin, Root> = () => (tree, file) => { +export const remarkMermaid: Plugin, Root> = () => (tree: Root) => { visit(tree, (node) => { if (node.type === "code" && node.lang === "mermaid") { // @ts-ignore diff --git a/src/markdown/remark-pangu.ts b/src/markdown/remark-pangu.ts index a245199d..fc4d95fe 100644 --- a/src/markdown/remark-pangu.ts +++ b/src/markdown/remark-pangu.ts @@ -28,7 +28,7 @@ function format(value: string) { export const remarkPangu: Plugin, Root> = (options = {}) => - (tree, _) => { + (tree: Root) => { const settings = Object.assign({}, defaultOptions, options) const subset = (Object.keys(settings) as Array).filter( (k) => settings[k], diff --git a/src/markdown/remark-youtube.ts b/src/markdown/remark-youtube.ts index 59b4a90a..2501f18c 100644 --- a/src/markdown/remark-youtube.ts +++ b/src/markdown/remark-youtube.ts @@ -2,51 +2,52 @@ import { Root } from "remark-gfm" import { Plugin } from "unified" import { visit } from "unist-util-visit" -export const remarkYoutube: Plugin, Root> = () => (tree, file) => { - visit(tree, (node) => { - if ( - node.type === "textDirective" || - node.type === "leafDirective" || - node.type === "containerDirective" - ) { - if (node.name !== "youtube") return +export const remarkYoutube: Plugin, Root> = + () => (tree: Root, file: any) => { + visit(tree, (node) => { + if ( + node.type === "textDirective" || + node.type === "leafDirective" || + node.type === "containerDirective" + ) { + if (node.name !== "youtube") return - const data = node.data || (node.data = {}) - const attributes = node.attributes || {} - const id = attributes.id + const data = node.data || (node.data = {}) + const attributes = node.attributes || {} + const id = attributes.id - if (node.type === "textDirective") - file.fail("Text directives for `youtube` not supported", node) - if (!id) file.fail("Missing video id", node) + if (node.type === "textDirective") + file.fail("Text directives for `youtube` not supported", node) + if (!id) + file.fail("Missing video id", node)(data as any).hName = + "div" as string + ;(data as any).hProperties = { + className: ["xlog-post-content-youtube"], + style: "position: relative; padding-bottom: 56.25%; height: 0;", + } - data.hName = "div" - data.hProperties = { - className: ["xlog-post-content-youtube"], - style: "position: relative; padding-bottom: 56.25%; height: 0;", - } - - node.children = [ - { - type: "leafDirective", - data: { - hName: "iframe", - hProperties: { - src: "https://www.youtube.com/embed/" + id, - width: 728, - height: 409.5, - frameBorder: 0, - allow: - "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture", - allowFullScreen: true, - title: "YouTube video player", - style: - "position: absolute; top: 0; left: 0; width: 100%; height: 100%;", + node.children = [ + { + type: "leafDirective", + data: { + hName: "iframe", + hProperties: { + src: "https://www.youtube.com/embed/" + id, + width: 728, + height: 409.5, + frameBorder: 0, + allow: + "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture", + allowFullScreen: true, + title: "YouTube video player", + style: + "position: absolute; top: 0; left: 0; width: 100%; height: 100%;", + }, }, + children: [], + name: "iframe", }, - children: [], - name: "iframe", - }, - ] - } - }) -} + ] + } + }) + }