journal/entries/index.php

95 lines
2.7 KiB
PHP

<?php
include __DIR__."/../vendor/autoload.php";
use tildeteam\wiki;
$parser = wiki::factory();
wiki::$bootstrap = wiki::$forkawesome = true;
if (isset($_GET["slug"])) {
$entry_name = $_GET["slug"];
} elseif (count($_GET) == 1) {
$entry_name = array_keys($_GET)[0];
} else {
$entry_name = "";
}
$filename = "{$entry_name}.md";
if (file_exists($filename)) {
$document = $parser->parse(file_get_contents($filename));
$yml = $document->getYAML();
$content = $document->getContent();
$title = $yml["title"] ?? "invalid";
$date = htmlspecialchars($yml["date"]);
$author_name = htmlspecialchars($yml["author_name"]);
if (isset($yml["author_link"])) {
$author_link = htmlspecialchars($yml["author_link"]);
$author = "<a href=\"$author_link\">$author_name</a>";
} else {
$author = $author_name;
}
if (isset($yml["original_link"])):
$original_link = htmlspecialchars($yml["original_link"]);
endif;
$description = "journal entry {$entry_name}: {$yml["title"]} by {$author}";
include __DIR__."/../header.php";
?>
<a href=".">&lt; back to list</a>
<h1>
<?=$title?>
<?=$yml["published"] ? "" : " <small><em>draft</em></small>" ?>
</h1>
<p>author: <?=$author?></p>
<p>date: <?=$date?></p>
<br />
<?php if (isset($original_link)): ?>
<p>Originally published at <a href="<?=$original_link?>"><?=$original_link?></a>.</p>
<br />
<?php endif; ?>
<?=$content?>
<?php
} else {
$title="journal entries";
$description="a list of tildeverse journal entries.";
include __DIR__."/../header.php";
foreach (glob("*.md") as $entry) {
$entries[] = [
"slug" => basename($entry, ".md"),
"yml" => $parser->parse(file_get_contents($entry))->getYAML(),
];
} ?>
<h1>journal entries</h1>
<ul>
<?php foreach ($entries as $entry) {
if (!$entry["yml"]["published"]) continue;
$title = $entry["yml"]["title"] ?? "invalid";
$date = htmlspecialchars($entry["yml"]["date"]);
$author_name = htmlspecialchars($entry["yml"]["author_name"]);
if (isset($entry["yml"]["author_link"])) {
$author_link = htmlspecialchars($entry["yml"]["author_link"]);
$author = "<a href=\"$author_link\">$author_name</a>";
} else {
$author = $author_name;
} ?>
<li>
<a href="/entries/<?=$entry["slug"]?>"><?=$title?></a>
by
<?=$author?>
&mdash;
<?=$date?>
</li>
<?php } ?>
</ul>
<?php }
include __DIR__."/../footer.php"; ?>