From 1da5cfb2eac8ebcdae49af5b5e729609143baee8 Mon Sep 17 00:00:00 2001 From: hypercross Date: Sat, 14 Mar 2026 10:27:07 +0800 Subject: [PATCH] refactor: article iconPath --- src/components/Article.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/Article.tsx b/src/components/Article.tsx index 4a711d7..f09f88e 100644 --- a/src/components/Article.tsx +++ b/src/components/Article.tsx @@ -1,12 +1,14 @@ -import { Component, createSignal, createEffect, onCleanup, Show, createResource } from 'solid-js'; +import { Component, createSignal, createEffect, onCleanup, Show, createResource, createMemo } from 'solid-js'; import { parseMarkdown } from '../markdown'; import { extractSection } from '../data-loader'; import mermaid from 'mermaid'; import {getIndexedData} from "../data-loader/file-index"; +import { resolvePath } from './utils/path'; export interface ArticleProps { src: string; section?: string; // 指定要显示的标题(不含 #) + iconPath?: string; // 图标路径前缀,默认为 "./assets",空字符串表示禁用 onLoaded?: () => void; onError?: (error: Error) => void; class?: string; // 额外的 class 用于样式控制 @@ -28,6 +30,12 @@ export const Article: Component = (props) => { fetchArticleContent ); + // 解析 iconPath,默认为 "./assets",空字符串表示禁用 + const iconPrefix = createMemo(() => { + if (props.iconPath === '') return undefined; // 空字符串禁用图标前缀 + return resolvePath(props.src, props.iconPath ?? "./assets"); + }); + createEffect(() => { const data = content(); if (data) { @@ -50,7 +58,7 @@ export const Article: Component = (props) => {
加载失败:{content.error?.message}
-
+
);