Skip to content

Commit

Permalink
Move hardcoded summary options to configuration file
Browse files Browse the repository at this point in the history
Fixes #175
  • Loading branch information
tobias-kuendig authored and daftspunk committed Apr 5, 2021
1 parent c624e19 commit 1418b03
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -183,6 +183,16 @@ The component can be used on any page, it will hijack the entire page cycle to d
==
<!-- This markup will never be displayed -->

## 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 `<!-- more -->`) 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/)
Expand All @@ -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:

~~~
Expand All @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Summary Config
|--------------------------------------------------------------------------
|
| Specify a custom tag and length for blog post summaries
|
*/

'summary_separator' => '<!-- more -->',

'summary_default_length' => 600

];
13 changes: 9 additions & 4 deletions models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Html;
use Lang;
use Model;
use Config;
use Markdown;
use BackendAuth;
use Carbon\Carbon;
Expand Down Expand Up @@ -371,12 +372,13 @@ public function scopeFilterCategories($query, $categories)
*/
public function getHasSummaryAttribute()
{
$more = '<!-- more -->';
$more = Config::get('rainlab.blog::summary_separator', '<!-- more -->');
$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
);
}

Expand All @@ -394,14 +396,17 @@ public function getSummaryAttribute()
return $excerpt;
}

$more = '<!-- more -->';
$more = Config::get('rainlab.blog::summary_separator', '<!-- more -->');

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);
}

//
Expand Down

0 comments on commit 1418b03

Please sign in to comment.