Compare commits

..

No commits in common. "fbc67175ae31e9b41b760dcaaa2050fe4067bc10" and "68d57ac0498e9e26353857fa7f4841cc2c19a39b" have entirely different histories.

3 changed files with 5 additions and 36 deletions

View File

@ -42,12 +42,9 @@ const App: Component = () => {
<h1 class="text-2xl font-bold text-gray-900">TTRPG Tools</h1> <h1 class="text-2xl font-bold text-gray-900">TTRPG Tools</h1>
</div> </div>
</header> </header>
{/* fill th rest of the space*/} <main class="max-w-4xl mx-auto px-4 py-8 pt-20 md:ml-64 2xl:ml-auto flex justify-center items-center">
<div class="fixed top-16 left-0 right-0 bottom-0 overflow-auto"> <Article class="prose-sm max-w-full flex-1" src={currentPath()} />
<main class="max-w-4xl mx-auto px-4 py-8 pt-4 md:ml-64 2xl:ml-auto flex justify-center items-center"> </main>
<Article class="prose-sm max-w-full flex-1" src={currentPath()} />
</main>
</div>
</div> </div>
); );
}; };

View File

@ -1,10 +1,9 @@
import { Component, createEffect, onCleanup, Show, createResource, createMemo } from 'solid-js'; import { Component, createSignal, createEffect, onCleanup, Show, createResource, createMemo } from 'solid-js';
import { parseMarkdown } from '../markdown'; import { parseMarkdown } from '../markdown';
import { extractSection } from '../data-loader'; import { extractSection } from '../data-loader';
import mermaid from 'mermaid'; import mermaid from 'mermaid';
import {getIndexedData} from "../data-loader/file-index"; import {getIndexedData} from "../data-loader/file-index";
import { resolvePath } from './utils/path'; import { resolvePath } from './utils/path';
import { useLocation } from '@solidjs/router';
export interface ArticleProps { export interface ArticleProps {
src: string; src: string;
@ -13,7 +12,6 @@ export interface ArticleProps {
onLoaded?: () => void; onLoaded?: () => void;
onError?: (error: Error) => void; onError?: (error: Error) => void;
class?: string; // 额外的 class 用于样式控制 class?: string; // 额外的 class 用于样式控制
scrollToHash?: boolean; // 是否自动滚动到 hash
} }
async function fetchArticleContent(params: { src: string; section?: string }): Promise<string> { async function fetchArticleContent(params: { src: string; section?: string }): Promise<string> {
@ -22,34 +20,11 @@ async function fetchArticleContent(params: { src: string; section?: string }): P
return params.section ? extractSection(text, params.section) : text; return params.section ? extractSection(text, params.section) : text;
} }
/**
* hash
*/
function scrollToHash(hash: string) {
if (!hash) return;
// 移除 # 前缀
const id = hash.startsWith('#') ? hash.slice(1) : hash;
if (!id) return;
// 使用 decodeURIComponent 解码 ID处理中文等特殊字符
const decodedId = decodeURIComponent(id);
// 尝试查找元素
const element = document.getElementById(decodedId);
if (element) {
// 使用 scrollIntoView 滚动到元素
element.scrollIntoView({ behavior: 'instant', block: 'start' });
return true;
}
return false;
}
/** /**
* Article * Article
* src md markdown * src md markdown
*/ */
export const Article: Component<ArticleProps> = (props) => { export const Article: Component<ArticleProps> = (props) => {
const location = useLocation();
const [content, { refetch }] = createResource( const [content, { refetch }] = createResource(
() => ({ src: props.src, section: props.section }), () => ({ src: props.src, section: props.section }),
fetchArticleContent fetchArticleContent
@ -67,9 +42,6 @@ export const Article: Component<ArticleProps> = (props) => {
props.onLoaded?.(); props.onLoaded?.();
// 内容加载完成后,渲染 mermaid 图表 // 内容加载完成后,渲染 mermaid 图表
void mermaid.run(); void mermaid.run();
// 内容渲染后检查 hash 并滚动
scrollToHash(location.hash);
} }
}); });

View File

@ -9,7 +9,7 @@ import type { MarkedExtension, Tokens } from "marked";
function tableToCSV(headers: string[], rows: string[][]): string { function tableToCSV(headers: string[], rows: string[][]): string {
const escapeCell = (cell: string) => { const escapeCell = (cell: string) => {
// 如果单元格包含逗号、换行或引号,需要转义 // 如果单元格包含逗号、换行或引号,需要转义
if (cell.includes(',') || cell.includes('\n') || cell.includes('"') || cell.includes("#")) { if (cell.includes(',') || cell.includes('\n') || cell.includes('"')) {
return `"${cell.replace(/"/g, '""')}"`; return `"${cell.replace(/"/g, '""')}"`;
} }
return cell; return cell;