From 9b72b5c316b38129952a4d59af05a0138ca1a15a Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Mon, 12 Dec 2016 14:49:05 +0100 Subject: [PATCH] Give pages starting with a underscore (_) a special treatment Follow-up to b493ebdb84e0da20e73ee21992ff36868be0008f --- content-sample/_meta.md | 12 ++++++++++++ content-sample/index.md | 10 ---------- lib/Pico.php | 20 ++++++++++++++++---- themes/default/index.twig | 4 ++-- 4 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 content-sample/_meta.md diff --git a/content-sample/_meta.md b/content-sample/_meta.md new file mode 100644 index 0000000..e43ed5e --- /dev/null +++ b/content-sample/_meta.md @@ -0,0 +1,12 @@ +--- +social: + - title: Visit us on GitHub + url: https://github.com/picocms/Pico + icon: octocat + - title: Check us out on Twitter + url: https://twitter.com/gitpicocms + icon: birdy + - title: Join us on Freenode IRC Webchat + url: https://webchat.freenode.net/?channels=%23picocms + icon: chat +--- \ No newline at end of file diff --git a/content-sample/index.md b/content-sample/index.md index d8d2f97..bb5d334 100644 --- a/content-sample/index.md +++ b/content-sample/index.md @@ -1,16 +1,6 @@ --- Title: Welcome Description: Pico is a stupidly simple, blazing fast, flat file CMS. -social: - - title: Visit us on GitHub - url: https://github.com/picocms/Pico - icon: octocat - - title: Check us out on Twitter - url: https://twitter.com/gitpicocms - icon: birdy - - title: Join us on Freenode IRC Webchat - url: https://webchat.freenode.net/?channels=%23picocms - icon: chat --- ## Welcome to Pico diff --git a/lib/Pico.php b/lib/Pico.php index 85388b1..c8db789 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -344,8 +344,11 @@ class Pico // load raw file content $this->triggerEvent('onContentLoading', array(&$this->requestFile)); - $notFoundFile = '404' . $this->getConfig('content_ext'); - if (file_exists($this->requestFile) && (basename($this->requestFile) !== $notFoundFile)) { + if ( + file_exists($this->requestFile) + && (basename($this->requestFile) !== '404' . $this->getConfig('content_ext')) + && !preg_match('/(?:^|\/)_/', $this->requestFile) + ) { $this->rawContent = $this->loadFileContent($this->requestFile); } else { $this->triggerEvent('on404ContentLoading', array(&$this->requestFile)); @@ -1294,6 +1297,7 @@ class Pico 'time' => &$meta['time'], 'date' => &$meta['date'], 'date_formatted' => &$meta['date_formatted'], + 'hidden' => (bool) preg_match('/(?:^|\/)_/', $id), 'raw_content' => &$rawContent, 'meta' => &$meta ); @@ -1331,6 +1335,10 @@ class Pico } $alphaSortClosure = function ($a, $b) use ($order) { + if ($a['hidden'] xor $b['hidden']) { + return (!!$a['hidden'] - !!$b['hidden']) * (($order === 'desc') ? -1 : 1); + } + $aSortKey = (basename($a['id']) === 'index') ? dirname($a['id']) : $a['id']; $bSortKey = (basename($b['id']) === 'index') ? dirname($b['id']) : $b['id']; @@ -1341,8 +1349,12 @@ class Pico if ($orderBy === 'date') { // sort by date uasort($this->pages, function ($a, $b) use ($alphaSortClosure, $order) { - if (empty($a['time']) || empty($b['time'])) { - $cmp = (empty($a['time']) - empty($b['time'])); + if ($a['hidden'] xor $b['hidden']) { + return $alphaSortClosure($a, $b); + } + + if (!$a['time'] || !$b['time']) { + $cmp = (!$a['time'] - !$b['time']); } else { $cmp = ($b['time'] - $a['time']); } diff --git a/themes/default/index.twig b/themes/default/index.twig index 084075e..4197e13 100644 --- a/themes/default/index.twig +++ b/themes/default/index.twig @@ -28,7 +28,7 @@