Skip to content

Commit

Permalink
ignore posts which were set as draft in the front-matter (#44)
Browse files Browse the repository at this point in the history
* ignore posts which were set as draft in the front-matter

* remove the nunjucks configs

* escape content

* rename to hexo-generator-xfeed

* fix jscs error

* remove the old-school node 0.12 from .travis.yml

* fix #41 according to http://stackoverflow.com/a/40552083/6056653

* Add the babel-eslint package to fix the eslint related issue. The eslint-config-hexo has a dependence on babel-eslint, but our project miss it.
  • Loading branch information
mamboer authored and NoahDragon committed Apr 24, 2017
1 parent 19ab397 commit 16398e5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules/
tmp/
*.log
.idea/
coverage/
coverage/
*.lock
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ cache:
- node_modules

node_js:
- "0.12"
- "4"
- "6"

Expand Down
2 changes: 1 addition & 1 deletion atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<published>{{ post.date.toISOString() }}</published>
<updated>{{ post.updated.toISOString() }}</updated>
{% if config.feed.content and post.content %}
<content type="html"><![CDATA[{{ post.content | safe }}]]></content>
<content type="html"><![CDATA[{{ post.content | noControlChars | safe }}]]></content>
{% endif %}
<summary type="html">
{% if post.description %}
Expand Down
8 changes: 8 additions & 0 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ env.addFilter('uriencode', function(str) {
return encodeURI(str);
});

env.addFilter('noControlChars', function(str) {
return str.replace(/[\x00-\x1F\x7F]/g, '');
});

var atomTmplSrc = pathFn.join(__dirname, '../atom.xml');
var atomTmpl = nunjucks.compile(fs.readFileSync(atomTmplSrc, 'utf8'), env);
var rss2TmplSrc = pathFn.join(__dirname, '../rss2.xml');
Expand All @@ -20,6 +24,10 @@ module.exports = function(locals) {
var template = feedConfig.type === 'rss2' ? rss2Tmpl : atomTmpl;

var posts = locals.posts.sort('-date');
posts = posts.filter(function(post) {
return post.draft !== true;
});

if (feedConfig.limit) posts = posts.limit(feedConfig.limit);

var url = config.url;
Expand Down
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-generator-feed",
"version": "1.2.0",
"version": "1.2.2",
"description": "Feed generator plugin for Hexo",
"main": "index",
"scripts": {
Expand All @@ -23,18 +23,19 @@
"author": "Tommy Chen <tommy351@gmail.com> (http://zespia.tw)",
"license": "MIT",
"dependencies": {
"nunjucks": "^2.4.1",
"object-assign": "^4.0.1"
"nunjucks": "^3.0.0",
"object-assign": "^4.1.1"
},
"devDependencies": {
"babel-eslint": "^7.2.3",
"chai": "^3.5.0",
"cheerio": "^0.20.0",
"cheerio": "^0.22.0",
"eslint": "^2.4.0",
"eslint-config-hexo": "^1.0.3",
"hexo": "^3.0.0",
"jscs": "^2.11.0",
"eslint-config-hexo": "^1.0.4",
"hexo": "^3.3.1",
"istanbul": "^0.4.5",
"jscs": "^3.0.7",
"jscs-preset-hexo": "^1.0.1",
"mocha": "^2.4.5",
"istanbul": "^0.4.2"
"mocha": "^3.2.0"
}
}
2 changes: 1 addition & 1 deletion rss2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% endif %}
</description>
{% if config.feed.content and post.content %}
<content:encoded><![CDATA[{{ post.content | safe }}]]></content:encoded>
<content:encoded><![CDATA[{{ post.content | noControlChars | safe }}]]></content:encoded>
{% endif %}
{% if post.comments %}<comments>{{ (url + post.path) | uriencode }}#disqus_thread</comments>{% endif %}
</item>
Expand Down
4 changes: 4 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ env.addFilter('uriencode', function(str) {
return encodeURI(str);
});

env.addFilter('noControlChars', function(str) {
return str.replace(/[\x00-\x1F\x7F]/g, '');
});

var atomTmplSrc = pathFn.join(__dirname, '../atom.xml');
var atomTmpl = nunjucks.compile(fs.readFileSync(atomTmplSrc, 'utf8'), env);
var rss2TmplSrc = pathFn.join(__dirname, '../rss2.xml');
Expand Down

0 comments on commit 16398e5

Please sign in to comment.