Skip to content

Commit

Permalink
Make default length of content configurable (#51)
Browse files Browse the repository at this point in the history
* added option for max length of feed content (previously fixed to 140); defaults to 140;

* bumped version to 1.2.1

* fixed config option reference;

* playing around with only cutting post content at delim for feed summary

* playing around with only cutting post content at delim for feed summary

* implemented content delimiter also for rss2; updated README and included new content_limit_delim option; bumped package version to 1.2.2;
  • Loading branch information
wiwie authored and NoahDragon committed Sep 6, 2017
1 parent 1b75605 commit cbe2672
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ feed:
limit: 20
hub:
content:
content_limit: 140
content_limit_delim: ' '
```
- **type** - Feed type. (atom/rss2)
- **path** - Feed path. (Default: atom.xml/rss2.xml)
- **limit** - Maximum number of posts in the feed (Use `0` or `false` to show all posts)
- **hub** - URL of the PubSubHubbub hubs (Leave it empty if you don't use it)
- **content** - (optional) set to 'true' to include the contents of the entire post in the feed.
- **content_limit** - (optional) Default length of post content used in summary. Only used, if **content** setting is false and no custom post description present.
- **content_limit_delim** - (optional) If **content_limit** is used to shorten post contents, only cut at the last occurrence of this delimiter before reaching the character limit. Not used by default.
12 changes: 11 additions & 1 deletion atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@
{% elif post.excerpt %}
{{ post.excerpt }}
{% elif post.content %}
{{ post.content.substring(0, 140) }}
{% set short_content = post.content.substring(0, config.feed.content_limit) %}
{% if config.feed.content_limit_delim %}
{% set delim_pos = short_content.lastIndexOf(config.feed.content_limit_delim) %}
{% if delim_pos > -1 %}
{{ short_content.substring(0, delim_pos) }}
{% else %}
{{ short_content }}
{% endif %}
{% else %}
{{ short_content }}
{% endif %}
{% endif %}
</summary>
{% for category in post.categories.toArray() %}
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ var config = hexo.config.feed = assign({
type: 'atom',
limit: 20,
hub: '',
content: true
content: true,
content_limit: 140,
content_limit_delim: ''
}, hexo.config.feed);

var type = config.type.toLowerCase();
Expand Down
12 changes: 11 additions & 1 deletion rss2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@
{% elif post.excerpt %}
{{ post.excerpt }}
{% elif post.content %}
{{ post.content.substring(0, 140) }}
{% set short_content = post.content.substring(0, config.feed.content_limit) %}
{% if config.feed.content_limit_delim %}
{% set delim_pos = short_content.lastIndexOf(config.feed.content_limit_delim) %}
{% if delim_pos > -1 %}
{{ short_content.substring(0, delim_pos) }}
{% else %}
{{ short_content }}
{% endif %}
{% else %}
{{ short_content }}
{% endif %}
{% endif %}
</description>
{% if config.feed.content and post.content %}
Expand Down

0 comments on commit cbe2672

Please sign in to comment.