refactor: move utils

This commit is contained in:
2026-02-27 12:40:50 +08:00
parent a409efaf95
commit 5638b6200b
6 changed files with 5 additions and 6 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
import { customElement, noShadowDOM } from 'solid-element';
import { createSignal, For, Show, createEffect, createMemo, createResource } from 'solid-js';
import { resolvePath } from '../utils/path';
import { resolvePath } from './utils/path';
import type { CardData, Dimensions } from './types';
import { loadCSV } from './utils/csv-loader';
import { initLayerConfigs } from './utils/layer-parser';
+2 -2
View File
@@ -2,7 +2,7 @@ import { customElement, noShadowDOM } from "solid-element";
import { createSignal, onCleanup } from "solid-js";
import { render } from "solid-js/web";
import { Article } from "./Article";
import { resolvePath } from "../utils/path";
import { resolvePath } from "./utils/path";
customElement("md-link", {}, (props, { element }) => {
noShadowDOM();
@@ -11,7 +11,7 @@ customElement("md-link", {}, (props, { element }) => {
const [expanded, setExpanded] = createSignal(false);
let articleContainer: HTMLDivElement | undefined;
let disposeArticle: (() => void) | null = null;
let articleElement: HTMLElement | undefined;
let articleElement: HTMLElement | null | undefined;
// 从 element 的 textContent 获取链接目标(支持 path#section 语法)
const rawLinkSrc = element?.textContent?.trim() || "";
+1 -1
View File
@@ -1,6 +1,6 @@
import { customElement, noShadowDOM } from "solid-element";
import { createSignal, onMount, onCleanup, Show, For, createResource, createMemo } from "solid-js";
import { resolvePath } from "../utils/path";
import { resolvePath } from "./utils/path";
interface Pin {
x: number;
+1 -1
View File
@@ -1,7 +1,7 @@
import { customElement, noShadowDOM } from 'solid-element';
import { createSignal, For, Show, createEffect, createMemo, createResource } from 'solid-js';
import { marked } from '../markdown';
import { resolvePath } from '../utils';
import { resolvePath } from './utils';
import { loadCSV } from './utils/csv-loader';
export interface TableProps {
+35
View File
@@ -0,0 +1,35 @@
/**
* 解析相对路径为绝对路径
* 支持 ./ 和 ../ 语法
* @param base - 基准路径(通常是当前 markdown 文件的路径)
* @param relative - 相对路径或绝对路径
* @returns 解析后的路径
*/
export function resolvePath(base: string, relative: string): string {
if (relative.startsWith('/')) {
return relative;
}
const baseParts = base.split('/').filter(Boolean);
// 移除文件名,保留目录路径
if (baseParts.length > 0 && !base.endsWith('/')) {
baseParts.pop();
}
const relativeParts = relative.split('/');
for (const part of relativeParts) {
if (part === '.' || part === '') {
// 跳过 . 和空字符串
continue;
} else if (part === '..') {
// 向上一级
baseParts.pop();
} else {
// 普通路径段
baseParts.push(part);
}
}
return '/' + baseParts.join('/');
}