diff --git a/README.md b/README.md index d9196f8..f96addd 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ Use the `blogCategories` component to display a list of blog post categories wit The component injects the following variables to the page where it's used: -* **categoryPage** - contains the value of the `categoryPage` component's property. +* **categoryPage** - contains the value of the `categoryPage` component's property. * **categories** - a list of blog categories loaded from the database. * **currentCategorySlug** - slug of the current category. This property is used for marking the current category in the category list. @@ -183,6 +183,16 @@ The component can be used on any page, it will hijack the entire page cycle to d == +## Configuration + +To overwrite the default configuration create a `config/rainlab/blog/config.php`. You can return only values you want to override. + +### Summary + +A summary attribute is generated for each post. + +If you enter an excerpt manually, it gets used as summary. Alternatively, you can use the `summary_separator` (default is ``) to mark the end of the summary. If a post contains no separator, the text gets truncated after the number of characters specified in `summary_default_length` (default is 600 characters). + ## Markdown guide October supports [standard markdown syntax](http://daringfireball.net/projects/markdown/) as well as [extended markdown syntax](http://michelf.ca/projects/php-markdown/extra/) @@ -205,7 +215,7 @@ Markdown extra makes it possible to use fenced code blocks. With fenced code blo ``` Code goes here ``` - + You can also use the `~` symbol: ~~~ @@ -219,8 +229,8 @@ A *simple* table can be defined as follows: ``` First Header | Second Header ------------- | ------------- -Content Cell | Content Cell -Content Cell | Content Cell +Content Cell | Content Cell +Content Cell | Content Cell ``` If you want to you can also add a leading and tailing pipe: diff --git a/config/config.php b/config/config.php new file mode 100644 index 0000000..bdf5743 --- /dev/null +++ b/config/config.php @@ -0,0 +1,18 @@ + '', + + 'summary_default_length' => 600 + +]; diff --git a/models/Post.php b/models/Post.php index 92ec833..5f7ee6c 100644 --- a/models/Post.php +++ b/models/Post.php @@ -4,6 +4,7 @@ use Html; use Lang; use Model; +use Config; use Markdown; use BackendAuth; use Carbon\Carbon; @@ -371,12 +372,13 @@ public function scopeFilterCategories($query, $categories) */ public function getHasSummaryAttribute() { - $more = ''; + $more = Config::get('rainlab.blog::summary_separator', ''); + $length = Config::get('rainlab.blog::summary_default_length', 600); return ( !!strlen(trim($this->excerpt)) || strpos($this->content_html, $more) !== false || - strlen(Html::strip($this->content_html)) > 600 + strlen(Html::strip($this->content_html)) > $length ); } @@ -394,14 +396,17 @@ public function getSummaryAttribute() return $excerpt; } - $more = ''; + $more = Config::get('rainlab.blog::summary_separator', ''); + if (strpos($this->content_html, $more) !== false) { $parts = explode($more, $this->content_html); return array_get($parts, 0); } - return Html::limit($this->content_html, 600); + $length = Config::get('rainlab.blog::summary_default_length', 600); + + return Html::limit($this->content_html, $length); } //