mirror of
https://github.com/danpros/htmly.git
synced 2026-04-23 05:56:22 +05:30
Bugs fixes and improvements
Bugs fixes and improvements. Multi author fixed, post sort by date fixed etc.
This commit is contained in:
parent
785f07c907
commit
8d4e2abf72
5 changed files with 87 additions and 87 deletions
|
|
@ -19,7 +19,7 @@ get('/index', function () {
|
||||||
$page = $page ? (int)$page : 1;
|
$page = $page ? (int)$page : 1;
|
||||||
$perpage = config('posts.perpage');
|
$perpage = config('posts.perpage');
|
||||||
|
|
||||||
$posts = get_posts($page, $perpage);
|
$posts = get_posts(null, $page, $perpage);
|
||||||
|
|
||||||
$total = '';
|
$total = '';
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ get('/tag/:tag',function($tag){
|
||||||
}
|
}
|
||||||
|
|
||||||
render('main',array(
|
render('main',array(
|
||||||
'title' => ucfirst($tag) .' - ' . config('blog.title'),
|
'title' => 'Tag - ' . ucfirst($tag) .' - ' . config('blog.title'),
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'posts' => $posts,
|
'posts' => $posts,
|
||||||
'canonical' => config('site.url') . '/tag/' . $tag,
|
'canonical' => config('site.url') . '/tag/' . $tag,
|
||||||
|
|
@ -122,16 +122,13 @@ get('/archive/:req',function($req){
|
||||||
// The blog post page
|
// The blog post page
|
||||||
get('/:year/:month/:name', function($year, $month, $name){
|
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);
|
$post = find_post($year, $month, $name);
|
||||||
|
|
||||||
// Extract a specific page with results
|
$current = $post['current'];
|
||||||
$post = array_slice($post, 0, $perpage);
|
|
||||||
|
|
||||||
$current = $post[0];
|
if(!$current){
|
||||||
|
not_found();
|
||||||
|
}
|
||||||
|
|
||||||
if (array_key_exists('prev', $post)) {
|
if (array_key_exists('prev', $post)) {
|
||||||
$prev = $post['prev'];
|
$prev = $post['prev'];
|
||||||
|
|
@ -181,7 +178,7 @@ get('/search/:keyword', function($keyword){
|
||||||
}
|
}
|
||||||
|
|
||||||
render('main',array(
|
render('main',array(
|
||||||
'title' => 'Search results for: ' . $keyword . ' - ' . config('blog.title'),
|
'title' => 'Search - ' . $keyword . ' - ' . config('blog.title'),
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
'posts' => $posts,
|
'posts' => $posts,
|
||||||
'canonical' => config('site.url') . '/search/' . $keyword,
|
'canonical' => config('site.url') . '/search/' . $keyword,
|
||||||
|
|
@ -253,7 +250,7 @@ get('/api/json',function(){
|
||||||
header('Content-type: application/json');
|
header('Content-type: application/json');
|
||||||
|
|
||||||
// Print the 10 latest posts as 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
|
// Show the RSS feed
|
||||||
|
|
@ -262,7 +259,7 @@ get('/feed/rss',function(){
|
||||||
header('Content-Type: application/rss+xml');
|
header('Content-Type: application/rss+xml');
|
||||||
|
|
||||||
// Show an RSS feed with the 30 latest posts
|
// 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')));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,78 +62,18 @@ function cmp($a, $b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return blog post
|
// Return blog post
|
||||||
function get_posts($page = 1, $perpage = 0){
|
function get_posts($posts, $page = 1, $perpage = 0){
|
||||||
|
|
||||||
$posts = get_post_names();
|
if(empty($posts)) {
|
||||||
|
|
||||||
$tmp = array();
|
$posts = get_post_names();
|
||||||
|
|
||||||
// Create a new instance of the markdown parser
|
$tmp = array();
|
||||||
$md = new MarkdownParser();
|
|
||||||
|
|
||||||
foreach($posts as $k=>$v){
|
// Create a new instance of the markdown parser
|
||||||
|
$md = new MarkdownParser();
|
||||||
|
|
||||||
$post = new stdClass;
|
foreach($posts as $k=>$v){
|
||||||
|
|
||||||
// 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]));
|
|
||||||
|
|
||||||
// The archive per day
|
|
||||||
$post->archive = site_url(). 'archive/' . date('Y-m-d', $post->date) ;
|
|
||||||
|
|
||||||
// The post URL
|
|
||||||
$post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]);
|
|
||||||
|
|
||||||
// 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('</h1>', $content);
|
|
||||||
$post->title = str_replace('<h1>','',$arr[0]);
|
|
||||||
$post->body = $arr[1];
|
|
||||||
|
|
||||||
$tmp[] = $post;
|
|
||||||
}
|
|
||||||
|
|
||||||
usort($tmp,'cmp');
|
|
||||||
|
|
||||||
// Extract a specific page with results
|
|
||||||
$tmp = array_slice($tmp, ($page-1) * $perpage, $perpage);
|
|
||||||
|
|
||||||
return $tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find post by year, month and name, previous, and next.
|
|
||||||
function find_post($year, $month, $name){
|
|
||||||
|
|
||||||
$posts = get_post_names();
|
|
||||||
$tmp = array();
|
|
||||||
|
|
||||||
// Create a new instance of the markdown parser
|
|
||||||
$md = new MarkdownParser();
|
|
||||||
|
|
||||||
foreach($posts as $index => $v){
|
|
||||||
if( strpos($v, "$year-$month") !== false && strpos($v, $name.'.md') !== false){
|
|
||||||
|
|
||||||
$post = new stdClass;
|
$post = new stdClass;
|
||||||
|
|
||||||
|
|
@ -176,10 +116,73 @@ function find_post($year, $month, $name){
|
||||||
|
|
||||||
$tmp[] = $post;
|
$tmp[] = $post;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
usort($tmp,'cmp');
|
usort($tmp,'cmp');
|
||||||
|
|
||||||
|
|
||||||
|
// Extract a specific page with results
|
||||||
|
$tmp = array_slice($tmp, ($page-1) * $perpage, $perpage);
|
||||||
|
|
||||||
|
return $tmp;
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
// Extract a specific page with results
|
||||||
|
$tmp = array_slice($posts, ($page-1) * $perpage, $perpage);
|
||||||
|
|
||||||
return $tmp;
|
return $tmp;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find post by year, month and name, previous, and next.
|
||||||
|
function find_post($year, $month, $name){
|
||||||
|
|
||||||
|
$posts = get_posts(null, null, null);
|
||||||
|
$tmp = $posts;
|
||||||
|
|
||||||
|
foreach ($tmp as $index => $v) {
|
||||||
|
$url = $v->url;
|
||||||
|
if (strpos($url, $year . '/' . $month . '/' . $name) !== false) {
|
||||||
|
|
||||||
|
// Use the get_posts method to return
|
||||||
|
// a properly parsed object
|
||||||
|
|
||||||
|
$ar = get_posts($posts, $index+1,1);
|
||||||
|
$nx = get_posts($posts, $index,1);
|
||||||
|
$pr = get_posts($posts, $index+2,1);
|
||||||
|
|
||||||
|
if ($index == 0) {
|
||||||
|
if(isset($pr[0])) {
|
||||||
|
return array(
|
||||||
|
'current'=> $ar[0],
|
||||||
|
'prev'=> $pr[0]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return array(
|
||||||
|
'current'=> $ar[0],
|
||||||
|
'prev'=> null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif (count($posts) == $index+1) {
|
||||||
|
return array(
|
||||||
|
'current'=> $ar[0],
|
||||||
|
'next'=> $nx[0]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return array(
|
||||||
|
'current'=> $ar[0],
|
||||||
|
'next'=> $nx[0],
|
||||||
|
'prev'=> $pr[0]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return tag page
|
// Return tag page
|
||||||
|
|
@ -377,7 +380,7 @@ function tag_cloud() {
|
||||||
echo '<h3>Tags</h3>';
|
echo '<h3>Tags</h3>';
|
||||||
echo '<ul class="taglist">';
|
echo '<ul class="taglist">';
|
||||||
foreach ($tag_collection as $tag => $count){
|
foreach ($tag_collection as $tag => $count){
|
||||||
echo '<li class="item"><a href="' . site_url() . 'tag/' . $tag . '">' . ucfirst($tag) . '</a> <span class="count">(' . $count . ')</span></li>';
|
echo '<li class="item"><a href="' . site_url() . 'tag/' . $tag . '">' . $tag . '</a> <span class="count">(' . $count . ')</span></li>';
|
||||||
}
|
}
|
||||||
echo '</ul>';
|
echo '</ul>';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
<div class="post <?php echo $class ?>" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
|
<div class="post <?php echo $class ?>" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
|
||||||
<div class="main">
|
<div class="main">
|
||||||
<h2 class="title-index" itemprop="name"><a href="<?php echo $p->url?>"><?php echo $p->title ?></a></h2>
|
<h2 class="title-index" itemprop="name"><a href="<?php echo $p->url?>"><?php echo $p->title ?></a></h2>
|
||||||
<div class="date"><span itemprop="datePublished"><?php echo date('d F Y', $p->date)?></span> - Posted in <span itemprop="articleSection"><a href="<?php echo $p->tagurl ?>"><?php echo ucfirst($p->tag) ?></a></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span><?php if (disqus_count() == true):?> - <span><a href="<?php echo $p->url?>#disqus_thread">Comments</a></span><?php endif;?></div>
|
<div class="date"><span itemprop="datePublished"><?php echo date('d F Y', $p->date)?></span> - Posted in <span itemprop="articleSection"><a href="<?php echo $p->tagurl ?>"><?php echo $p->tag ?></a></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span><?php if (disqus_count() == true):?> - <span><a href="<?php echo $p->url?>#disqus_thread">Comments</a></span><?php endif;?></div>
|
||||||
<div itemprop="articleBody">
|
<div itemprop="articleBody">
|
||||||
<?php if (config('img.thumbnail') == 'true'):?>
|
<?php if (config('img.thumbnail') == 'true'):?>
|
||||||
<?php echo get_thumbnail($p->body)?>
|
<?php echo get_thumbnail($p->body)?>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
<?php endif;?>
|
<?php endif;?>
|
||||||
<h1 class="title-post" itemprop="name"><?php echo $p->title ?></h1>
|
<h1 class="title-post" itemprop="name"><?php echo $p->title ?></h1>
|
||||||
<?php if ($type == 'blogpost'):?>
|
<?php if ($type == 'blogpost'):?>
|
||||||
<div class="date"><span itemprop="datePublished"><a href="<?php echo $p->archive ?>" title="Show all posts made on this day"><?php echo date('d F Y', $p->date)?></a></span> - Posted in <span itemprop="articleSection"><a href="<?php echo $p->tagurl ?>"><?php echo ucfirst($p->tag) ?></a></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span> - <span><a href="<?php echo $p->url ?>" rel="permalink">Permalink</a></span></div>
|
<div class="date"><span itemprop="datePublished"><a href="<?php echo $p->archive ?>" title="Show all posts made on this day"><?php echo date('d F Y', $p->date)?></a></span> - Posted in <span itemprop="articleSection"><a href="<?php echo $p->tagurl ?>"><?php echo $p->tag ?></a></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span> - <span><a href="<?php echo $p->url ?>" rel="permalink">Permalink</a></span></div>
|
||||||
<?php endif;?>
|
<?php endif;?>
|
||||||
<div itemprop="articleBody">
|
<div itemprop="articleBody">
|
||||||
<?php echo $p->body; ?>
|
<?php echo $p->body; ?>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?php if (!empty($breadcrumb)):?><div class="breadcrumb"><?php echo $breadcrumb ?></div><?php endif;?>
|
<?php if (!empty($breadcrumb)):?><div class="breadcrumb"><?php echo $breadcrumb ?></div><?php endif;?>
|
||||||
<div class="profile">
|
<div class="profile" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="Person">
|
||||||
<h1 class="title-post"><?php echo $name ?></h1>
|
<h1 class="title-post" itemprop="name"><?php echo $name ?></h1>
|
||||||
<div class="bio"><?php echo $bio ?></div>
|
<div class="bio" itemprop="description"><?php echo $bio ?></div>
|
||||||
</div>
|
</div>
|
||||||
<h2 class="post-index">Posts by this author</h2>
|
<h2 class="post-index">Posts by this author</h2>
|
||||||
<ul class="post-list">
|
<ul class="post-list">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue