浏览代码

Update pico.php

This is only a suggestion and could be expanded and changed but for my project and what I'm working on this seemed good enough.

Essentially this allows the possibility for the Date: meta field within the markdown content files to be written in various ways which will all be converted to ISO YYYY-MM-DD-ID before being sorted. This should also in theory speed up the process on much larger sites.

Additionally, I've changed how files without a date are sorted within the array: by the date the page was last modified. 

So essentially the logic goes:

if meta.date then meta.date else page.modified > sort

This could be expanded to allow the date modified to be read by the date_formatted or what have you, however it could break some people's sites whereby they utilise various data attribute within twig. Though one would assume they would be doing this on the date meta identifier. 

Anyhow, food for thought.

- Andrew
:)
Andrew Tajsic 12 年之前
父节点
当前提交
7dcc2b6ed9
共有 1 个文件被更改,包括 3 次插入2 次删除
  1. 3 2
      lib/pico.php

+ 3 - 2
lib/pico.php

@@ -236,7 +236,8 @@ class Pico {
 				'excerpt' => $this->limit_words(strip_tags($page_content), $excerpt_length)
 			);
 			if($order_by == 'date'){
-				$sorted_pages[$page_meta['date'].$date_id] = $data;
+				$date_sort = (empty($page_meta['date'])) ? date("o-m-d", filemtime($page)) : date("o-m-d", strtotime($page_meta['date']));
+				$sorted_pages[$date_sort . "-" . $date_id] = $data;
 				$date_id++;
 			}
 			else $sorted_pages[] = $data;
@@ -336,4 +337,4 @@ class Pico {
 
 }
 
-?>
+?>