web: docs reads all .md from docs/md/ dynamically (no hardcoded map)

docs/index.php now scans docs/md/*.md, uses each file's first '# heading' (or the
filename) as the tree label, and renders the selected page on the right. The
hardcoded group/page map is gone; adding/removing an .md under md/ updates the
left file tree automatically. .md sources moved into docs/md/.
这个提交包含在:
JGZYES
2026-09-05 12:02:59 +08:00
父节点 b3e48338c1
当前提交 eec6113d38
修改 9 个文件,包含 21 行新增32 行删除
+21 -32
查看文件
@@ -1,38 +1,31 @@
<?php <?php
/* PMM docs site — left sidebar directory + right rendered .md content. /* PMM docs site — scans md/*.md into a left file tree and renders the selected
* URL: docs/index.php?page=<name> (defaults to "index"). */ * page on the right. URL: docs/index.php?page=<slug> (defaults to "index"). */
define('PMM_SITE', 1); define('PMM_SITE', 1);
require dirname(__DIR__) . '/_common.php'; require dirname(__DIR__) . '/_common.php';
/* doc pages: [slug, title] — grouped sections */ $mdDir = __DIR__ . '/md';
$groups = [
'开始' => [ /* Discover every .md file; title = first "# " line, else the filename. */
'index' => '快速开始', $pages = []; // slug -> title
'install' => '安装', if (is_dir($mdDir)) {
'download'=> '下载', foreach (glob($mdDir . '/*.md') as $f) {
], $slug = basename($f, '.md');
'了解' => [ $title = $slug;
'features' => '核心特性', $raw = (string)file_get_contents($f);
'cli' => '命令参考', if (preg_match('/^#\s+(.+)$/m', $raw, $m)) $title = trim($m[1]);
'mirror' => '镜像源', $pages[$slug] = $title;
], }
'社区' => [ }
'translate' => '翻译 / 语言包',
'source' => '源码',
],
];
// flatten for page lookup
$pages = [];
foreach ($groups as $g => $list) foreach ($list as $slug => $t) $pages[$slug] = $t;
$page = isset($_GET['page']) ? (string)$_GET['page'] : 'index'; $page = isset($_GET['page']) ? (string)$_GET['page'] : 'index';
if (!isset($pages[$page])) $page = 'index'; if (!isset($pages[$page])) $page = 'index';
$title = $pages[$page]; $title = $pages[$page];
$mdPath = __DIR__ . '/' . $page . '.md';
$body = ''; $body = '';
if (is_file($mdPath)) { $f = $mdDir . '/' . $page . '.md';
$body = (string)file_get_contents($mdPath); if (is_file($f)) {
$body = (string)file_get_contents($f);
$body = str_replace("\r", "", $body); // md() regex hard-codes \n $body = str_replace("\r", "", $body); // md() regex hard-codes \n
$body = md($body); $body = md($body);
} }
@@ -40,11 +33,10 @@ if (is_file($mdPath)) {
pmm_header('docs', '文档 · ' . $title); pmm_header('docs', '文档 · ' . $title);
?> ?>
<style> <style>
/* docs layout — inline so it works regardless of external style.css state */ /* docs layout — inline, so it works regardless of external style.css state */
.docs-layout{display:grid;grid-template-columns:240px minmax(0,1fr);gap:28px;max-width:1160px;margin:0 auto;padding:28px 22px 60px;align-items:start} .docs-layout{display:grid;grid-template-columns:240px minmax(0,1fr);gap:28px;max-width:1160px;margin:0 auto;padding:28px 22px 60px;align-items:start}
.docs-sidebar{position:sticky;top:14px;min-width:0;border-right:1px solid #282828;padding-right:16px} .docs-sidebar{position:sticky;top:14px;min-width:0;border-right:1px solid #282828;padding-right:16px}
.docs-sidebar-brand{font-weight:700;font-size:15px;color:#fff;padding:0 4px 12px;border-bottom:1px solid #282828;margin-bottom:8px} .docs-sidebar-brand{font-weight:700;font-size:15px;color:#fff;padding:0 4px 12px;border-bottom:1px solid #282828;margin-bottom:8px}
.docs-group{font-size:11px;letter-spacing:1.2px;text-transform:uppercase;color:#555;padding:14px 6px 6px}
.docs-tree{display:block} .docs-tree{display:block}
.docs-tree a.docs-link{display:block;font-size:14px;color:#9a9a9a;text-decoration:none;padding:7px 10px;border-radius:7px;margin:0} .docs-tree a.docs-link{display:block;font-size:14px;color:#9a9a9a;text-decoration:none;padding:7px 10px;border-radius:7px;margin:0}
.docs-tree a.docs-link:hover{color:#fff;background:#101010} .docs-tree a.docs-link:hover{color:#fff;background:#101010}
@@ -74,11 +66,8 @@ pmm_header('docs', '文档 · ' . $title);
<aside class="docs-sidebar"> <aside class="docs-sidebar">
<div class="docs-sidebar-brand"><span>PMM 文档</span></div> <div class="docs-sidebar-brand"><span>PMM 文档</span></div>
<nav class="docs-tree"> <nav class="docs-tree">
<?php foreach ($groups as $g => $list): ?> <?php foreach ($pages as $slug => $t): ?>
<div class="docs-group"><?php echo htmlspecialchars($g); ?></div> <a class="docs-link<?php echo $slug === $page ? ' active' : ''; ?>" href="index.php?page=<?php echo $slug; ?>"><?php echo htmlspecialchars($t); ?></a>
<?php foreach ($list as $slug => $t): ?>
<a class="docs-link<?php echo $slug === $page ? ' active' : ''; ?>" href="index.php?page=<?php echo $slug; ?>"><?php echo htmlspecialchars($t); ?></a>
<?php endforeach; ?>
<?php endforeach; ?> <?php endforeach; ?>
</nav> </nav>
</aside> </aside>