From 14c99275f7a43c3db31ea4b3d29b7b64a7356749 Mon Sep 17 00:00:00 2001 From: DefectingCat Date: Thu, 4 Jan 2024 10:51:50 +0800 Subject: [PATCH] add find children href url in paragraph --- components/mdx/components.ts | 2 ++ components/mdx/paragraph.tsx | 26 ++++++++++++++++++++++++ content/posts/musl-cross-compilation.mdx | 2 ++ 3 files changed, 30 insertions(+) create mode 100644 components/mdx/paragraph.tsx diff --git a/components/mdx/components.ts b/components/mdx/components.ts index 0733f7f..7f1e1d6 100644 --- a/components/mdx/components.ts +++ b/components/mdx/components.ts @@ -7,11 +7,13 @@ import RUASandpack from 'components/rua/rua-sandpack'; import Tab from 'components/rua/tab'; import TabItem from 'components/rua/tab/tab-item'; import GistCode from 'components/common/gist-code'; +import Paragraph from 'components/mdx/paragraph'; const components = { RUASandpack, a: Anchor, pre: Pre, + p: Paragraph, Image, Tab, TabItem, diff --git a/components/mdx/paragraph.tsx b/components/mdx/paragraph.tsx new file mode 100644 index 0000000..1f61c1a --- /dev/null +++ b/components/mdx/paragraph.tsx @@ -0,0 +1,26 @@ +import React from 'react'; +import { HTMLAttributes } from 'react'; + +const Paragraph = (props: HTMLAttributes) => { + const { children, ...rest } = props; + + // Find anchor href url in children + const links = React.Children.map(children, (child) => { + if (!React.isValidElement(child)) return null; + if (typeof child.type !== 'object') return null; + const childType = child.type as any; + if (!childType?.type) return null; + if (childType.type.render.displayName !== 'Anchor') return null; + const props = child.props as { href: string }; + return props.href; + }); + + return ( + <> +

{children}

+ {links?.map((url, i) =>
{url}
)} + + ); +}; + +export default Paragraph; diff --git a/content/posts/musl-cross-compilation.mdx b/content/posts/musl-cross-compilation.mdx index 8f58660..189e752 100644 --- a/content/posts/musl-cross-compilation.mdx +++ b/content/posts/musl-cross-compilation.mdx @@ -4,6 +4,8 @@ date: '2023-12-26' tags: [Rust, Linux] --- +test [rua](https://rua.plus) test [rua](https://rua.plus) test [rua](https://rua.plus) + 大多数 Linux 软件都是动态链接的,动态链接可以使我们的程序不需要将所有所需要的库都打包到自身当中去。不过这样也有弊处,当目标系统比较旧,或者压根就没有我们需要的库的时候,我们的二进制文件就无法在目标系统中运行。 ## 安装交叉编译工具