fix: better php
This commit is contained in:
parent
c8b4ac408e
commit
4c28ae5063
5 changed files with 47 additions and 27 deletions
|
@ -61,11 +61,13 @@ omnisrv-9p -site src -proto unix -addr /tmp/omnisrv
|
||||||
|
|
||||||
新頁面放在 `src/page`。
|
新頁面放在 `src/page`。
|
||||||
|
|
||||||
PHP 模板在 `tpl/*.php`;omnisrv 模板為 `tmpl.html`。
|
PHP 模板在 `tpl/*.php`;omnisrv 模板在 `src/tmpl.html`。
|
||||||
|
|
||||||
一級標題在 `/page` 頁面自動列出。
|
一級標題在 `/page` 頁面自動列出。
|
||||||
|
|
||||||
與 dummy-ssg 不同,Markdown 文檔頭部使用簡易鍵值對,而非 JSON:
|
與 dummy-ssg 標準不同,資源文件放在 `src/assets` 並且直接鏈接 (`<link href="/assets/..." />`),而非放入 `tpl`。
|
||||||
|
|
||||||
|
同時,倉庫中的 Markdown 文檔頭部使用簡易鍵值對,而非 JSON:
|
||||||
|
|
||||||
```
|
```
|
||||||
---
|
---
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
{{- .Html -}}
|
{{- .Html -}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
</main>
|
</main>
|
||||||
|
{{if .Footer}}<footer>{{.Footer}}</footer>{{end}}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,8 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<!-- Powered by dummy-ssg -->
|
<!-- Powered by dummy-ssg -->
|
||||||
<?php
|
<?php
|
||||||
// let's use simple key-value headers instead of json
|
[$main, $footer] = split($page['content']);
|
||||||
$raw = file_get_contents("src/" . $page["path"]);
|
$page = kvhead($page);
|
||||||
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];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
?>
|
||||||
<html lang="<?php if (empty($page["lang"])) echo "zh-TW"; else echo $page["lang"]; ?>">
|
<html lang="<?php if (empty($page["lang"])) echo "zh-TW"; else echo $page["lang"]; ?>">
|
||||||
<head>
|
<head>
|
||||||
|
@ -30,9 +18,12 @@
|
||||||
<?php
|
<?php
|
||||||
if ($page["path"] === "index.md") include "bio.php";
|
if ($page["path"] === "index.md") include "bio.php";
|
||||||
else if ($page["path"] === "page/index.md") include "page-index.php";
|
else if ($page["path"] === "page/index.md") include "page-index.php";
|
||||||
else if (!empty($page["content"])) echo $page["content"];
|
else if (!empty($main)) echo $main;
|
||||||
else echo "此頁為空";
|
else echo "此頁為空";
|
||||||
?>
|
?>
|
||||||
</main>
|
</main>
|
||||||
|
<?php if (!empty($footer)) { ?>
|
||||||
|
<footer><?= $footer ?></footer>
|
||||||
|
<?php } ?>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
33
tpl/init.php
Normal file
33
tpl/init.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// from https://codeberg.org/fsfans-cn/www/src/branch/new/template/init.php
|
||||||
|
function split($parsed) {
|
||||||
|
$hrtag = '<hr />';
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -32,15 +32,8 @@ array_multisort(
|
||||||
<?php echo $page["content"] ?>
|
<?php echo $page["content"] ?>
|
||||||
<table class="pages">
|
<table class="pages">
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php
|
<?php foreach ($child_pages as $page) { ?>
|
||||||
foreach ($child_pages as $page)
|
<tr><td><?= date("Y-m-d", $page["date"]) ?></td><td><a href="<?= $page["href"] ?>"><?= $page["title"] ?></a></td></tr>
|
||||||
echo "<tr><td>",
|
<?php } ?>
|
||||||
date("Y-m-d", $page["date"]),
|
|
||||||
"</td><td><a href=\"",
|
|
||||||
$page["href"],
|
|
||||||
"\">",
|
|
||||||
$page["title"],
|
|
||||||
"</a></td></tr>\n";
|
|
||||||
?>
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue