diff --git a/system/htmly.php b/system/htmly.php index 08d6c2a..df7cc7e 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -19,7 +19,7 @@ get('/index', function () { $page = $page ? (int)$page : 1; $perpage = config('posts.perpage'); - $posts = get_posts($page, $perpage); + $posts = get_posts(null, $page, $perpage); $total = ''; @@ -59,7 +59,7 @@ get('/tag/:tag',function($tag){ } render('main',array( - 'title' => ucfirst($tag) .' - ' . config('blog.title'), + 'title' => 'Tag - ' . ucfirst($tag) .' - ' . config('blog.title'), 'page' => $page, 'posts' => $posts, 'canonical' => config('site.url') . '/tag/' . $tag, @@ -122,16 +122,13 @@ get('/archive/:req',function($req){ // The blog post page get('/:year/:month/:name', function($year, $month, $name){ - $page = from($_GET, 'page'); - $page = $page ? (int)$page : 1; - $perpage = 1; - $post = find_post($year, $month, $name); - // Extract a specific page with results - $post = array_slice($post, 0, $perpage); + $current = $post['current']; - $current = $post[0]; + if(!$current){ + not_found(); + } if (array_key_exists('prev', $post)) { $prev = $post['prev']; @@ -181,7 +178,7 @@ get('/search/:keyword', function($keyword){ } render('main',array( - 'title' => 'Search results for: ' . $keyword . ' - ' . config('blog.title'), + 'title' => 'Search - ' . $keyword . ' - ' . config('blog.title'), 'page' => $page, 'posts' => $posts, 'canonical' => config('site.url') . '/search/' . $keyword, @@ -253,7 +250,7 @@ get('/api/json',function(){ header('Content-type: application/json'); // Print the 10 latest posts as JSON - echo generate_json(get_posts(1, config('json.count'))); + echo generate_json(get_posts(null, 1, config('json.count'))); }); // Show the RSS feed @@ -262,7 +259,7 @@ get('/feed/rss',function(){ header('Content-Type: application/rss+xml'); // Show an RSS feed with the 30 latest posts - echo generate_rss(get_posts(1, config('rss.count'))); + echo generate_rss(get_posts(null, 1, config('rss.count'))); }); diff --git a/system/includes/functions.php b/system/includes/functions.php index 664266f..321b226 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -62,78 +62,18 @@ function cmp($a, $b) { } // Return blog post -function get_posts($page = 1, $perpage = 0){ +function get_posts($posts, $page = 1, $perpage = 0){ - $posts = get_post_names(); - - $tmp = array(); - - // Create a new instance of the markdown parser - $md = new MarkdownParser(); - - foreach($posts as $k=>$v){ - - $post = new stdClass; + if(empty($posts)) { - // Extract the date - $arr = explode('_', $v); - - // Replaced string - $replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/'; - - // Author string - $str = explode('/', $replaced); - $author = $str[count($str)-3]; - - // The post author + author url - $post->author = $author; - $post->authorurl = site_url() . 'author/' . $author; - - // The post date - $post->date = strtotime(str_replace($replaced,'',$arr[0])); + $posts = get_post_names(); - // The archive per day - $post->archive = site_url(). 'archive/' . date('Y-m-d', $post->date) ; + $tmp = array(); - // The post URL - $post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]); + // Create a new instance of the markdown parser + $md = new MarkdownParser(); - // The post tag - $post->tag = str_replace($replaced,'',$arr[1]); - - // The post tag url - $post->tagurl = site_url(). 'tag/' . $arr[1]; - - // Get the contents and convert it to HTML - $content = $md->transformMarkdown(file_get_contents($v)); - - // Extract the title and body - $arr = explode('', $content); - $post->title = str_replace('