journal/entries/index.php

76 lines
2.0 KiB
PHP
Raw Normal View History

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