fix: better php
This commit is contained in:
parent
c8b4ac408e
commit
4c28ae5063
5 changed files with 47 additions and 27 deletions
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;
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue