Skip to content

Commit cbe2672

Browse files
wiwieNoahDragon
authored andcommitted
Make default length of content configurable (#51)
* 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;
1 parent 1b75605 commit cbe2672

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ feed:
2828
limit: 20
2929
hub:
3030
content:
31+
content_limit: 140
32+
content_limit_delim: ' '
3133
```
3234
3335
- **type** - Feed type. (atom/rss2)
3436
- **path** - Feed path. (Default: atom.xml/rss2.xml)
3537
- **limit** - Maximum number of posts in the feed (Use `0` or `false` to show all posts)
3638
- **hub** - URL of the PubSubHubbub hubs (Leave it empty if you don't use it)
3739
- **content** - (optional) set to 'true' to include the contents of the entire post in the feed.
40+
- **content_limit** - (optional) Default length of post content used in summary. Only used, if **content** setting is false and no custom post description present.
41+
- **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.

atom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,17 @@
3131
{% elif post.excerpt %}
3232
{{ post.excerpt }}
3333
{% elif post.content %}
34-
{{ post.content.substring(0, 140) }}
34+
{% set short_content = post.content.substring(0, config.feed.content_limit) %}
35+
{% if config.feed.content_limit_delim %}
36+
{% set delim_pos = short_content.lastIndexOf(config.feed.content_limit_delim) %}
37+
{% if delim_pos > -1 %}
38+
{{ short_content.substring(0, delim_pos) }}
39+
{% else %}
40+
{{ short_content }}
41+
{% endif %}
42+
{% else %}
43+
{{ short_content }}
44+
{% endif %}
3545
{% endif %}
3646
</summary>
3747
{% for category in post.categories.toArray() %}

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ var config = hexo.config.feed = assign({
88
type: 'atom',
99
limit: 20,
1010
hub: '',
11-
content: true
11+
content: true,
12+
content_limit: 140,
13+
content_limit_delim: ''
1214
}, hexo.config.feed);
1315

1416
var type = config.type.toLowerCase();

rss2.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@
2222
{% elif post.excerpt %}
2323
{{ post.excerpt }}
2424
{% elif post.content %}
25-
{{ post.content.substring(0, 140) }}
25+
{% set short_content = post.content.substring(0, config.feed.content_limit) %}
26+
{% if config.feed.content_limit_delim %}
27+
{% set delim_pos = short_content.lastIndexOf(config.feed.content_limit_delim) %}
28+
{% if delim_pos > -1 %}
29+
{{ short_content.substring(0, delim_pos) }}
30+
{% else %}
31+
{{ short_content }}
32+
{% endif %}
33+
{% else %}
34+
{{ short_content }}
35+
{% endif %}
2636
{% endif %}
2737
</description>
2838
{% if config.feed.content and post.content %}

0 commit comments

Comments
 (0)