fixed current page
current page was find by title which could be duplicated in some files, so changed to the url which is unique
This commit is contained in:
parent
cf4fd9024f
commit
c825e107a3
1 changed files with 16 additions and 5 deletions
21
lib/pico.php
21
lib/pico.php
|
@ -66,7 +66,7 @@ class Pico {
|
|||
$current_page = array();
|
||||
$next_page = array();
|
||||
while($current_page = current($pages)){
|
||||
if($meta['title'] == $current_page['title']){
|
||||
if($this->gen_url($file) == $current_page['url']){
|
||||
break;
|
||||
}
|
||||
next($pages);
|
||||
|
@ -223,12 +223,9 @@ class Pico {
|
|||
$page_content = file_get_contents($page);
|
||||
$page_meta = $this->read_file_meta($page_content);
|
||||
$page_content = $this->parse_content($page_content);
|
||||
$url = str_replace(CONTENT_DIR, $base_url .'/', $page);
|
||||
$url = str_replace('index'. CONTENT_EXT, '', $url);
|
||||
$url = str_replace(CONTENT_EXT, '', $url);
|
||||
$data = array(
|
||||
'title' => $page_meta['title'],
|
||||
'url' => $url,
|
||||
'url' => $this->gen_url($page),
|
||||
'author' => $page_meta['author'],
|
||||
'date' => $page_meta['date'],
|
||||
'date_formatted' => date($config['date_format'], strtotime($page_meta['date'])),
|
||||
|
@ -333,6 +330,20 @@ class Pico {
|
|||
$words = explode(' ',$string);
|
||||
return trim(implode(' ', array_splice($words, 0, $word_limit))) .'...';
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to generate page url
|
||||
*
|
||||
* @param string $page a content file
|
||||
* @return string the absolute url to the file
|
||||
*/
|
||||
private function gen_url($page)
|
||||
{
|
||||
$url = str_replace(CONTENT_DIR, $this->base_url() .'/', $page);
|
||||
$url = str_replace('index'. CONTENT_EXT, '', $url);
|
||||
$url = str_replace(CONTENT_EXT, '', $url);
|
||||
return $url;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue