Last active
August 29, 2015 14:03
-
-
Save mattbeck/1604156ada969dea9947 to your computer and use it in GitHub Desktop.
Markdown Handling index.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query_string = $_SERVER['QUERY_STRING']; | |
$uri = filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_STRING); | |
$uri = str_ireplace('?'.$query_string, "", $uri); | |
$uri = rtrim($uri, '/'); // strip trailing slashes | |
if($uri !== ""){ | |
// Check if matching markdown file exists | |
$mdfilename = $uri.'.md'; | |
if(!file_exists(getcwd().$mdfilename)){ | |
// 404 | |
error_log($mdfilename); | |
header("HTTP/1.0 404 Not Found"); | |
$mdfilename = '404.md'; | |
} | |
} | |
else{ | |
// This is the homepage | |
$mdfilename = 'home.md'; | |
} | |
// Markdown Parser | |
include('inc/Parsedown.php'); | |
include('inc/ParsedownExtra.php'); | |
// My Functions | |
include('inc/Functions.php'); | |
?> | |
<html lang="en"> | |
<head> | |
<title><?php echo camelToTitleCase($mdfilename); ?> | Site Name</title> | |
<meta charset="utf-8"> | |
<link rel="stylesheet" media="all" href="/style.css"> | |
<link rel="stylesheet" media="print" href="/print.css"> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> | |
</head> | |
<body id="top"> | |
<a href="#top" id="back-top">back to top</a> | |
<div id="wrapper"> | |
<?php | |
echo ' | |
<header> | |
<h3 id="main-title"><a href="/">The Title</a></h3> | |
<nav>'.getMenu().'</nav> | |
</header>'; | |
$content_id = str_replace(array('.md', '/'),array('',''),$mdfilename); | |
echo '<div class="content" id="'.$content_id.'">'; | |
$mdfilepath = realpath(getcwd().'/'.$mdfilename); | |
$markdown = file_get_contents($mdfilepath); | |
$Parsedown = new ParsedownExtra(); | |
echo $Parsedown->text($markdown); | |
echo '</div>'; | |
// Process search results | |
if(isset($_GET['term']) && $content_id=='search'){ | |
include('search.php'); | |
} | |
?> | |
<footer> | |
footer stuff here | |
</footer> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment