Add draft viewer (for in-development RFCs)

TODO: have it fetch from gitea
This commit is contained in:
Robert Miles 2018-08-28 16:43:50 -04:00
parent 4b5462c2ee
commit e487929503
1 changed files with 32 additions and 0 deletions

32
draft.php Normal file
View File

@ -0,0 +1,32 @@
<?php
include 'vendor/autoload.php';
class MDParse implements Mni\FrontYAML\Markdown\MarkdownParser {
public function parse($markdown) {
return Michelf\MarkdownExtra::defaultTransform($markdown);
}
}
$parser = new Mni\FrontYAML\Parser(null, new MDParse());
$filename = 'draft-'.$_GET["name"].'.md';
if (!file_exists($filename)) {
header("Location: https://rfc.tildeverse.org/");
die();
}
$document = $parser->parse(file_get_contents($filename));
$yml = $document->getYAML();
$content = $document->getContent();
$title = ($yml['title'] ?? 'invalid');
$author_san = htmlspecialchars($yml['author']);
$description = "Draft {$_GET['name']}: {$yml['title']} by {$author_san}";
include 'header.php';
?>
<h1>Draft <?=$_GET['name']?>: <?=$yml['title']?></h1>
<p>Author: <?=htmlspecialchars($yml['author'])?><br />
<?php if(isset($yml['updates'])){?>
Updates: <?php $arr=explode(", ",$yml['updates']); foreach($arr as $num) { echo "<a href='./rfc.php?number={$num}'>{$num}</a>"; if(next($arr)) { echo ", "; }}?><br />
<?php };?>
<?php if(isset($yml['updated-by'])){?>
Updated by: <?php $arr=explode(", ",$yml['updated-by']); foreach($arr as $num) { echo "<a href='./rfc.php?number={$num}'>{$num}</a>"; if(next($arr)) { echo ", "; }}?><br />
<?php };?>
<?=$content?>
<?php include 'footer.php'; ?>