mirror of https://github.com/tildeclub/site.git
Pull out category frontmatter from articles and sort index by categories
This commit is contained in:
parent
bddf5ef406
commit
97344236c5
|
@ -8,17 +8,37 @@ include __DIR__."/../header.php";
|
||||||
<p>here's the articles on our wiki:</p>
|
<p>here's the articles on our wiki:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<?php
|
<?php
|
||||||
$article_to_title = [];
|
$category_to_articles = [];
|
||||||
foreach (glob("source/*.md") as $file) {
|
foreach (glob("source/*.md") as $file) {
|
||||||
$article = basename($file, ".md");
|
$article = basename($file, ".md");
|
||||||
$title = preg_match("/title: (.*)/i", file_get_contents($file), $matches) ? $matches[1] : $article;
|
$title = preg_match("/title: (.*)/i", file_get_contents($file), $matches) ? $matches[1] : $article;
|
||||||
$article_to_title[$article] = $title;
|
$category = preg_match("/category: (.*)/i", file_get_contents($file), $matches) ? $matches[1] : 'default';
|
||||||
|
if (array_key_exists($category, $category_to_articles)) {
|
||||||
|
array_push($category_to_articles[$category], [$article, $title]);
|
||||||
|
} else {
|
||||||
|
$category_to_articles[$category] = [[$article, $title]];
|
||||||
|
}
|
||||||
|
ksort($category_to_articles);
|
||||||
}
|
}
|
||||||
asort($article_to_title);
|
|
||||||
?>
|
?>
|
||||||
<?php foreach ($article_to_title as $article => $title) { ?>
|
<?php foreach ($category_to_articles as $category => $articles) { ?>
|
||||||
<li><a href="/wiki/<?=$article?>.html"><?=$title?></a></li>
|
<li><?=$category?></li>
|
||||||
<?php } ?>
|
<ul>
|
||||||
|
<?php
|
||||||
|
$article_titles = [];
|
||||||
|
$article_names = [];
|
||||||
|
foreach ($articles as $article) {
|
||||||
|
array_push($article_names, $article[0]);
|
||||||
|
array_push($article_titles, $article[1]);
|
||||||
|
}
|
||||||
|
$name_to_title = array_combine($article_names, $article_titles);
|
||||||
|
asort($name_to_title);
|
||||||
|
foreach ($name_to_title as $name => $title) { ?>
|
||||||
|
<li><a href="/wiki/<?=$name?>.html"><?=$title?></a></li>
|
||||||
|
<?php } ?>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<?php } ?>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<?php include __DIR__."/../footer.php";
|
<?php include __DIR__."/../footer.php";
|
||||||
|
|
Loading…
Reference in New Issue