From cfe324ce8d42c3c7f036315f1f74978c819444b8 Mon Sep 17 00:00:00 2001 From: "Masaki.Nakano" Date: Sun, 30 Jun 2024 01:50:26 +0900 Subject: [PATCH] clean --- packages/web/.prettierignore | 3 + packages/web/.prettierrc.mjs | 1 + packages/web/astro.config.ts | 15 +---- packages/web/src/pages/index.webp.ts | 2 +- packages/web/src/pages/post/[...slug].webp.ts | 2 +- packages/web/src/pages/post/index.webp.ts | 2 +- packages/web/src/pages/post/tag/[tag].webp.ts | 2 +- packages/web/src/remark/plugin/link-card.ts | 60 ------------------- 8 files changed, 9 insertions(+), 78 deletions(-) create mode 100644 packages/web/.prettierignore delete mode 100644 packages/web/src/remark/plugin/link-card.ts diff --git a/packages/web/.prettierignore b/packages/web/.prettierignore new file mode 100644 index 00000000..044ff4ec --- /dev/null +++ b/packages/web/.prettierignore @@ -0,0 +1,3 @@ +.astro +dist +node_modules \ No newline at end of file diff --git a/packages/web/.prettierrc.mjs b/packages/web/.prettierrc.mjs index a977d5a5..dc592f9a 100644 --- a/packages/web/.prettierrc.mjs +++ b/packages/web/.prettierrc.mjs @@ -1,3 +1,4 @@ +/** @type {import("prettier").Config} */ export default { plugins: ["prettier-plugin-astro", "@trivago/prettier-plugin-sort-imports"], }; diff --git a/packages/web/astro.config.ts b/packages/web/astro.config.ts index 947f29d7..caddc361 100644 --- a/packages/web/astro.config.ts +++ b/packages/web/astro.config.ts @@ -1,4 +1,3 @@ -import remarkLinkCard from "./src/remark/plugin/link-card"; import mdx from "@astrojs/mdx"; import sitemap from "@astrojs/sitemap"; import icon from "astro-icon"; @@ -26,13 +25,7 @@ export default defineConfig({ }), ], markdown: { - remarkPlugins: [ - remarkSectionize, - remarkGemoji, - remarkGfm, - remarkMath, - remarkLinkCard, - ], + remarkPlugins: [remarkSectionize, remarkGemoji, remarkGfm, remarkMath], rehypePlugins: [ rehypeKatex, rehypeSlug, @@ -42,12 +35,6 @@ export default defineConfig({ ], ], syntaxHighlight: false, - shikiConfig: { - themes: { - light: "github-light", - dark: "github-dark", - }, - }, smartypants: true, }, vite: { diff --git a/packages/web/src/pages/index.webp.ts b/packages/web/src/pages/index.webp.ts index e7e501e1..7d78910c 100644 --- a/packages/web/src/pages/index.webp.ts +++ b/packages/web/src/pages/index.webp.ts @@ -1,5 +1,5 @@ -import { ogArticlePreviewSVG } from "ogp-image"; import type { APIRoute } from "astro"; +import { ogArticlePreviewSVG } from "ogp-image"; export const GET: APIRoute = async ({ site }) => { return await ogArticlePreviewSVG({ diff --git a/packages/web/src/pages/post/[...slug].webp.ts b/packages/web/src/pages/post/[...slug].webp.ts index 3280d8e6..5e505e1c 100644 --- a/packages/web/src/pages/post/[...slug].webp.ts +++ b/packages/web/src/pages/post/[...slug].webp.ts @@ -1,6 +1,6 @@ -import { ogArticlePreviewSVG } from "ogp-image"; import type { APIRoute, GetStaticPaths } from "astro"; import { getCollection, getEntry } from "astro:content"; +import { ogArticlePreviewSVG } from "ogp-image"; export const getStaticPaths = (async () => { const collection = await getCollection("post", (post) => post.data.publish); diff --git a/packages/web/src/pages/post/index.webp.ts b/packages/web/src/pages/post/index.webp.ts index ba8c9a80..0e5d7852 100644 --- a/packages/web/src/pages/post/index.webp.ts +++ b/packages/web/src/pages/post/index.webp.ts @@ -1,5 +1,5 @@ -import { ogArticlePreviewSVG } from "ogp-image"; import type { APIRoute } from "astro"; +import { ogArticlePreviewSVG } from "ogp-image"; export const GET: APIRoute = async ({ site }) => { return await ogArticlePreviewSVG({ diff --git a/packages/web/src/pages/post/tag/[tag].webp.ts b/packages/web/src/pages/post/tag/[tag].webp.ts index 5f64851b..c19f28f6 100644 --- a/packages/web/src/pages/post/tag/[tag].webp.ts +++ b/packages/web/src/pages/post/tag/[tag].webp.ts @@ -1,6 +1,6 @@ -import { ogArticlePreviewSVG } from "ogp-image"; import type { APIRoute, GetStaticPaths } from "astro"; import { getCollection } from "astro:content"; +import { ogArticlePreviewSVG } from "ogp-image"; export const getStaticPaths = (async () => { const posts = await getCollection("post", (post) => post.data.publish); diff --git a/packages/web/src/remark/plugin/link-card.ts b/packages/web/src/remark/plugin/link-card.ts deleted file mode 100644 index a4c98e49..00000000 --- a/packages/web/src/remark/plugin/link-card.ts +++ /dev/null @@ -1,60 +0,0 @@ -// https://github.com/haxibami/haxibami.net/blob/main/src/lib/mdast-util-node-is.ts -import type { Root } from "mdast"; -import type { Paragraph, Link, Text, Literal } from "mdast"; -import type { Plugin } from "unified"; -import type { Node } from "unist"; -import { visit } from "unist-util-visit"; - -function isObject(node: unknown): node is Record { - return typeof node === "object" && node !== null; -} - -function isNode(node: unknown): node is Node { - return isObject(node) && "type" in node; -} - -function isParagraph(node: unknown): node is Paragraph { - return isNode(node) && node.type === "paragraph"; -} - -function isLink(node: unknown): node is Link { - return isNode(node) && node.type === "link"; -} - -function isLiteral(node: unknown): node is Literal { - return isObject(node) && "value" in node && "type" in node; -} - -function isText(node: unknown): node is Text { - return isLiteral(node) && node.type === "text"; -} - -function isIsolatedLink(node: unknown): node is Paragraph & { - children: [Link & { children: [Text] }]; -} { - return ( - isParagraph(node) && - node.children.length === 1 && - isLink(node.children[0]) && - node.children[0].children.every(isText) - ); -} - -function markIsolatedLink(tree: Root) { - visit(tree, isIsolatedLink, (node) => { - const link = node.children[0]; - link.data = { - ...link.data, - hProperties: { - ...link.data?.hProperties, - dataLinkCard: "true", - }, - }; - }); -} - -const plugin: Plugin<[], Root> = () => { - return markIsolatedLink; -}; - -export default plugin;