wiki/index.php

97 lines
2.8 KiB
PHP

<?php
$filepath = __FILE__;
require __DIR__.'/../vendor/autoload.php';
$additional_head = "
<style>
:target:before {
content:\"\";
display:block;
height:50px; /* fixed header height*/
margin:-50px 0 0; /* negative fixed header height */
}
</style>
<meta property='og:type' content='website'>
<meta property='og:image' content='https://tilde.cafe/apple-icon.png'>
<meta property='og:site_name' content='tilde.cafe wiki'>
";
$parser = Tildeverse\Wiki\Parser::factory();
// if it's tilde.cafe's live site, use wiki/wiki-page else use wiki/?page=wiki-page
if($_SERVER["HTTP_HOST"] == "tilde.cafe"){
// only use slashes if it's tilde.cafe/wiki/
// don't care if there's anything after that, such as an open wikipage
if(explode("/",rtrim($_GET["REQUEST_URI"],"/"),3)[1] == "wiki"){
// it's the official site
$format="";
} else {
// it's a userdir
$format="?page=";
// $format="";
}
} else {
// it's a different domain
$format="?page=";
}
if (!isset($_GET["page"]) || !file_exists("pages/{$_GET['page']}.md")) {
$title = "~cafe wiki";
$additional_head .= "
<meta property='og:title' content='$title'>
<meta property='og:url' content='https://tilde.cafe{$_SERVER['REQUEST_URI']}'>
<meta property='og:description' content='tilde.cafe wiki'>
";
include __DIR__.'/../header.php';
// render wiki index ?>
<h1>~wiki</h1>
<p>Welcome to the tilde.cafe wiki!</p>
<p>If you want to contribute, check out the
<a href="https://tildegit.org/cafe/wiki">source</a> and open a PR!
</p>
<hr>
<h3>pages:</h3>
<ul>
<?php
foreach (glob("pages/*.md") as $page) {
$yaml = $parser->parse(file_get_contents($page))->getYAML();
if (!$yaml["published"]) continue; ?>
<li><a href="<?php echo(strtok($_SERVER["REQUEST_URI"], '?').$format.basename($page, ".md"));?>"><?=$yaml["title"]?></a><br></li>
<?php }
echo("</ul></div>");
} else {
$pg = $parser->parse(file_get_contents("pages/{$_GET["page"]}.md"));
$yml = $pg->getYAML();
$title = $yml['title'] . " | tilde.cafe~wiki";
$description = $yml['description'] ?? "tilde.cafe wiki article {$yml['title']}";
$additional_head .= "
<meta property='og:title' content='$title'>
<meta property='og:url' content='https://tilde.cafe{$_SERVER['REQUEST_URI']}'>
<meta property='og:description' content='$description'>
";
include __DIR__.'/../header.php';
// show a single page ?>
<a href=".">&lt; ~wiki</a>
<hr>
<?=$pg->getContent()?>
<hr>
<a href="https://tildegit.org/cafe/wiki/src/branch/main/pages/<?=$_GET["page"]?>.md">
<i class="fa fa-edit"></i> source
</a>
<?php }
echo("</body></html>");
//include __DIR__.'/../footer.php';
?>