amaharacya.one/tpl/page-index.php
2025-09-30 02:43:14 +08:00

39 lines
1 KiB
PHP

<?php
// modified from https://codeberg.org/fsfans-cn/www/src/branch/new/template/dirlisting.php
$child_pages = [];
foreach (get_page_list("page") as $path) {
$child_page = get_page($path);
if (
(isset($child_page["unlisted"]) && $child_page["unlisted"])
|| $page["path"] == $path
) continue;
$href = "/" . substr_replace($child_page["path"], "html", -2);
if ($pos = strrpos($href, "/index.html")) {
$href = substr($href, 0, $pos + 1);
}
$date = 0;
if (!empty($child_page["date"]))
$date = date_create($child_page["date"]);
else
$date = filemtime("src/" . $child_page["path"]);
array_push($child_pages, [
"title" => $child_page["title"],
"date" => $date,
"href" => $href
]);
}
array_multisort(
array_column($child_pages, "date"), SORT_DESC,
$child_pages
);
?>
<?php echo $page["content"] ?>
<table class="pages">
<tbody>
<?php foreach ($child_pages as $page) { ?>
<tr><td><?= date("Y-m-d", $page["date"]) ?></td><td><a href="<?= $page["href"] ?>"><?= $page["title"] ?></a></td></tr>
<?php } ?>
</tbody>
</table>