Sort wiki articles by actual title instead of filename

This commit is contained in:
Travis Briggs 2020-04-12 01:09:33 -07:00
parent 24b0fdd592
commit ea181def2f
1 changed files with 10 additions and 6 deletions

View File

@ -7,14 +7,18 @@ include __DIR__."/../header.php";
<p>here's the articles on our wiki:</p>
<ul>
<?php foreach (glob("source/*.md") as $file) {
$article = basename($file, ".md");
$title = preg_match("/title: (.*)/i", file_get_contents($file), $matches)
? $matches[1] : $article;
?>
<?php
$article_to_title = [];
foreach (glob("source/*.md") as $file) {
$article = basename($file, ".md");
$title = preg_match("/title: (.*)/i", file_get_contents($file), $matches) ? $matches[1] : $article;
$article_to_title[$article] = $title;
}
sort($article_to_title);
?>
<?php foreach ($article_to_title as $article => $title) { ?>
<li><a href="/wiki/<?=$article?>.html"><?=$title?></a></li>
<?php } ?>
</ul>
<?php include __DIR__."/../footer.php";