From a6790cace37edd2f19a064cced3be8fc779e9493 Mon Sep 17 00:00:00 2001 From: Sommerregen Date: Sun, 1 Feb 2015 18:15:24 +0100 Subject: [PATCH] Added summary option --- system/src/Grav/Common/Page/Page.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 3f2dcc0dc5..19c63eb610 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -308,26 +308,32 @@ public function summary($size = null) return $content; } + // Get summary size from site config's file + if (is_null($size)) { + $size = $config->get('site.summary.size', null); + } + // Return calculated summary based on summary divider's position - if (!$size && isset($this->summary_size)) { + $format = $config->get('site.summary.format', 'short'); + // Return entire page content on wrong/ unknown format + if (!in_array($format, array('short', 'long'))) { + return $content; + } elseif (($format === 'short') && isset($this->summary_size)) { return substr($content, 0, $this->summary_size); } - // Return calculated summary based on setting in site config file - if (is_null($size) && $config->get('site.summary.size')) { - $size = $config->get('site.summary.size'); + // If the size is zero, return the entire page content + if ($size === 0) { + return $content; } - // Return calculated summary based on defaults - if (!is_numeric($size) || ($size < 0)) { + elseif (!is_numeric($size) || ($size < 0)) { $size = 300; } return Utils::truncateHTML($content, $size); } - - /** * Gets and Sets the content based on content portion of the .md file *