ttrpg-tools/src/App.tsx

49 lines
1.4 KiB
TypeScript
Raw Normal View History

2026-02-26 14:51:26 +08:00
import { Component, createMemo, createSignal } from "solid-js";
2026-02-26 14:07:58 +08:00
import { useLocation } from "@solidjs/router";
2026-02-26 00:17:23 +08:00
2026-02-26 00:47:26 +08:00
// 导入组件以注册自定义元素
2026-02-26 14:07:58 +08:00
import "./components";
2026-02-26 14:24:48 +08:00
import { Article, Sidebar } from "./components";
2026-02-26 00:47:26 +08:00
2026-02-26 00:17:23 +08:00
const App: Component = () => {
const location = useLocation();
2026-02-26 14:24:48 +08:00
const [isSidebarOpen, setIsSidebarOpen] = createSignal(false);
2026-02-26 00:17:23 +08:00
2026-02-26 14:51:26 +08:00
const currentPath = createMemo(() => {
2026-02-26 00:17:23 +08:00
// 根据路由加载对应的 markdown 文件
2026-02-26 14:07:58 +08:00
let path = decodeURIComponent(location.pathname);
if (!path) path = "/content/";
if (path.endsWith("/")) path += "index";
if (!path.endsWith(".md")) path += ".md";
2026-02-26 14:51:26 +08:00
return path;
2026-02-26 00:17:23 +08:00
});
return (
<div class="min-h-screen bg-gray-50">
2026-02-26 14:24:48 +08:00
<Sidebar
isOpen={isSidebarOpen()}
onClose={() => setIsSidebarOpen(false)}
/>
<header class="fixed top-0 left-0 right-0 bg-white shadow z-30">
<div class="max-w-4xl mx-auto px-4 py-4 flex items-center gap-4">
<button
onClick={() => setIsSidebarOpen(true)}
class="text-gray-600 hover:text-gray-900 p-1 rounded hover:bg-gray-100"
title="目录"
>
</button>
2026-02-26 00:17:23 +08:00
<h1 class="text-2xl font-bold text-gray-900">TTRPG Tools</h1>
</div>
</header>
2026-02-26 10:26:04 +08:00
<main class="max-w-4xl mx-auto px-4 py-8 pt-20">
2026-02-26 09:24:26 +08:00
<Article src={currentPath()} />
2026-02-26 00:17:23 +08:00
</main>
</div>
);
};
export default App;