Files
main/wiki/index.php
2026-06-22 16:02:50 +02:00

72 lines
1.6 KiB
PHP

<?php
include '../header.php';
include '../parsedown/Parsedown.php';
include '../parsedown-extra/ParsedownExtra.php';
$Parsedown = new Parsedown();
$Parsedown->setMarkupEscaped(true);
$Extra = new ParsedownExtra();
?>
<div id="top-bar">
<h1>> Wiki</h1>
</div>
<article id="content">
<p>Artykuły na naszej wiki:</p>
<?php
$categories = ['tylda', 'poradniki', 'technologia', 'linki'];
$category_to_articles = [];
foreach (glob("source/*.md") as $file)
{
$article = basename($file, ".md");
$title = preg_match("/title: (.*)/i", file_get_contents($file), $matches) ? $matches[1] : $article;
$title = ucfirst($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);
}
foreach ($categories as $category)
{
echo '<b> > '.ucwords($category).'</b>';
echo '<ul>';
$article_titles = [];
$article_names = [];
foreach ($category_to_articles[$category] 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)
echo '<li><a href="/wiki/page.php?article='.$name.'">'.$title.'</a></li>';
echo '</ul><br>';
}
?>
<p>Artykuły są publiczne pod licencją <a href=./COPYRIGHT.md>CC BY-NC-SA 4.0</a>.</p>
</article>
<?php
include '../footer.php';
?>