From 4c28ae5063c032bbcaa0d43397f44e26058ffa4c Mon Sep 17 00:00:00 2001 From: NaitLee Date: Tue, 30 Sep 2025 02:43:14 +0800 Subject: [PATCH] fix: better php --- README.md | 6 ++++-- src/tmpl.html | 1 + tpl/default.php | 21 ++++++--------------- tpl/init.php | 33 +++++++++++++++++++++++++++++++++ tpl/page-index.php | 13 +++---------- 5 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 tpl/init.php diff --git a/README.md b/README.md index bccca69..9c4e64a 100644 --- a/README.md +++ b/README.md @@ -61,11 +61,13 @@ omnisrv-9p -site src -proto unix -addr /tmp/omnisrv 新頁面放在 `src/page`。 -PHP 模板在 `tpl/*.php`;omnisrv 模板為 `tmpl.html`。 +PHP 模板在 `tpl/*.php`;omnisrv 模板在 `src/tmpl.html`。 一級標題在 `/page` 頁面自動列出。 -與 dummy-ssg 不同,Markdown 文檔頭部使用簡易鍵值對,而非 JSON: +與 dummy-ssg 標準不同,資源文件放在 `src/assets` 並且直接鏈接 (``),而非放入 `tpl`。 + +同時,倉庫中的 Markdown 文檔頭部使用簡易鍵值對,而非 JSON: ``` --- diff --git a/src/tmpl.html b/src/tmpl.html index a284571..863886c 100644 --- a/src/tmpl.html +++ b/src/tmpl.html @@ -19,6 +19,7 @@ {{- .Html -}} {{- end}} + {{if .Footer}}{{end}} diff --git a/tpl/default.php b/tpl/default.php index de861c5..c1b677d 100644 --- a/tpl/default.php +++ b/tpl/default.php @@ -1,20 +1,8 @@ "> @@ -30,9 +18,12 @@ + + + \ No newline at end of file diff --git a/tpl/init.php b/tpl/init.php new file mode 100644 index 0000000..8b4739d --- /dev/null +++ b/tpl/init.php @@ -0,0 +1,33 @@ +'; + $hrpos = strrpos($parsed, $hrtag); + if ($hrpos !== false) { + return [ + substr($parsed, 0, $hrpos), + substr($parsed, $hrpos + strlen($hrtag)) + ]; + } + return [$parsed, '']; +} + +function kvhead($page) { + $raw = file_get_contents("src/" . $page["path"]); + preg_match('/^---\n\s*(.*?)\s*\n---\n/s', $raw, $matches); + if (!empty($matches[1])) { + foreach (explode("\n", $matches[1]) as $line) { + $line = trim($line); + if ($line === '') continue; + $kv = explode(' ', $line, 2); + if (empty($kv[1])) + $page[$kv[0]] = true; + else + $page[$kv[0]] = $kv[1]; + } + } + return $page; +} + +?> \ No newline at end of file diff --git a/tpl/page-index.php b/tpl/page-index.php index 8496410..b155d02 100644 --- a/tpl/page-index.php +++ b/tpl/page-index.php @@ -32,15 +32,8 @@ array_multisort( - \n"; - ?> + + +
", - date("Y-m-d", $page["date"]), - "", - $page["title"], - "
">