-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
39 lines (30 loc) · 1.29 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php require __DIR__ . '/vendor/autoload.php';
/* Change content folder, i.e. '/docs' */
define('CONTENT_DIR', realpath(dirname(__FILE__)).'/');
$content = '';
$parser = new Parsedown();
if($url = trim(strpos($url = $_SERVER["REQUEST_URI"], 'index.php') > 0 ? substr($url,10) : $url, '/')) {
/* Get the file path. If a folder, attempt to locate README.md */
$path = CONTENT_DIR . $url;
$path .= @is_dir($path) ? "/README.md" : '';
$extension = @pathinfo($path)['extension'];
$content = @file_exists($path) ? @file_get_contents($path) : '';
/* Wrap the content inside a suitable markdown based on mime type (text, image etc) */
list($type, $subtype) = explode('/', @mime_content_type($path));
switch($type){
case "image" :
$content = $parser->text("![](/$url)");
break;
case "text" :
$content = $parser->text($extension === 'md' ? $content : "```$extension\n$content\n```" );
break;
default :
$content = "<pre>$content</pre>";
break;
}
/* Otherwise, report missing content (404)! */
$content = $content ? : $parser->text("## Error 404 :\n\nThe page is not found");
}
header('Content-type: text/html; charset=utf-8');
empty($content) ? include 'resources/views/layout-shell.php' :
include 'resources/views/markdown-shell.php';