Permalink
Browse files

support html pages

  • Loading branch information...
1 parent 5f294c0 commit 2c0206ad0f673ff2c527717a9fe5d55a1eb8b88a @juliend2 committed Mar 8, 2012
Showing with 14 additions and 8 deletions.
  1. +1 −0 config.php
  2. +5 −3 index.php
  3. +8 −5 lib/totoro.php
View
@@ -7,6 +7,7 @@
'blog_description' => "This is a brand new Totoro Blog.",
'theme' => 'default',
'posts_dir' => './posts',
+ 'pages_dir' => './pages',
'cache_dir' => './cache',
'max' => 150,
'posts_per_page' => 2,
View
@@ -39,11 +39,13 @@
header("HTTP/1.0 404 Not Found");
}
// pages
- } elseif (preg_match('/^\/([^\.\/]+)/i', $_GET['uri'], $matches) && file_exists('pages/'.$matches[1].'.md')) {
+ } elseif (preg_match('/^\/([^\.\/]+)/i', $_GET['uri'], $matches) &&
+ (file_exists('pages/'.$matches[1].'.md') || file_exists('pages/'.$matches[1].'.html')) ) {
$section_name = $matches[1];
- $page_file = 'pages/'.$matches[1].'.md';
+ $ext = get_extension($matches[1], true);
+ $page_file = 'pages/'.$matches[1].'.'.$ext;
if (file_exists($page_file)) {
- $page_content = get_html(@file_get_contents($page_file), 'md');
+ $page_content = get_html(@file_get_contents($page_file), $ext);
$view = "./themes/{$config['theme']}/page.php";
include "./themes/{$config['theme']}/layout.php";
} else {
View
@@ -4,6 +4,7 @@
include 'lib/php-markdown/markdown.php';
define('POSTS_DIR', $config['posts_dir']);
+define('PAGES_DIR', $config['pages_dir']);
ini_set('date.timezone', $config['date.timezone']);
// get the post's URL
@@ -26,14 +27,15 @@ function get_post_settings($post_header) {
}
// takes a file's basename and return it's extension if it exists
-function get_extension($basename) {
- if (file_exists(POSTS_DIR."/$basename.textile")) {
+function get_extension($basename, $is_page=false) {
+ $base_dir = $is_page ? PAGES_DIR : POSTS_DIR;
+ if (file_exists($base_dir."/$basename.textile")) {
return 'textile';
- } elseif (file_exists(POSTS_DIR."/$basename.md")) {
+ } elseif (file_exists($base_dir."/$basename.md")) {
return 'md';
- } elseif (file_exists(POSTS_DIR."/$basename.markdown")) {
+ } elseif (file_exists($base_dir."/$basename.markdown")) {
return 'markdown';
- } elseif (file_exists(POSTS_DIR."/$basename.html")) {
+ } elseif (file_exists($base_dir."/$basename.html")) {
return 'html';
} else { // file not found
return false;
@@ -62,6 +64,7 @@ function get_post($year, $month, $day, $slug, $ext='textile') {
// get html from (markdown|textile|html) string
function get_html($string, $ext) {
+ if ($ext == 'html') return $string;
// set function to be called to compile in HTML:
if ($ext == 'md' || $ext == 'markdown') { $func = 'Markdown'; }
elseif ($ext == 'textile') { $func = $ext; }

0 comments on commit 2c0206a

Please sign in to comment.