hexo-generator-feed
hexo-generator-feed copied to clipboard
Generate feeds by categories?
In addition to the whole website, if it possible to generate separate feeds by different categories? Like WP: http://codex.wordpress.org/WordPress_Feeds
Any update on it?
It seems that somebody have to write one and push the commit by itself if it want...
I would also like to have a feed based on either a category or a tag.
I really want this feature at least for category .
I found the hexo-generator-category-feed, but don't worked here with Hexo 3.0.1. Any idea?
The hexo-generator-category-feed is not compatible with Hexo 3.x. I forked it and made some changes. Now it works for me with Hexo 3.x. See https://github.com/zklhp/hexo-generator-category-feed.
@zklhp you can add this to the site~
Wouldn't something like
diff -up hexo-generator-feed/lib/generator.js.noCat hexo-generator-feed/lib/generator.js
--- hexo-generator-feed/lib/generator.js.noCat 2015-06-22 00:53:57.252358394 +0200
+++ hexo-generator-feed/lib/generator.js 2015-06-22 00:55:27.556153242 +0200
@@ -15,10 +15,18 @@ module.exports = function(locals){
var config = this.config;
var feedConfig = config.feed;
var template = feedConfig.type === 'rss2' ? rss2Tmpl : atomTmpl;
+ var posts;
- var posts = locals.posts.sort('-date');
- if (feedConfig.limit) posts = posts.limit(feedConfig.limit);
+ if (feedConfig.category) {
+ posts = locals.posts.categories('politics').sort('-date');
+ }
+ else {
+ posts = locals.posts.sort('-date');
+ }
+ if (feedConfig.limit) {
+ posts = posts.limit(feedConfig.limit);
+ }
var xml = template({
config: config,
work?
@mcepl The code seems okay. I encourage you to write a test case for it and submit a PR.
And I modified a bit:
diff -up hexo-generator-feed/lib/generator.js.noCat hexo-generator-feed/lib/generator.js
--- hexo-generator-feed/lib/generator.js.noCat 2015-06-22 00:53:57.252358394 +0200
+++ hexo-generator-feed/lib/generator.js 2015-06-22 00:55:27.556153242 +0200
@@ -15,10 +15,18 @@ module.exports = function(locals){
var config = this.config;
var feedConfig = config.feed;
var template = feedConfig.type === 'rss2' ? rss2Tmpl : atomTmpl;
- var posts = locals.posts.sort('-date');
+ var posts = locals.posts;
+ if (feedConfig.category) {
+ posts = posts.categories('politics');
+ }
+ posts = posts.sort('-date');
- if (feedConfig.limit) posts = posts.limit(feedConfig.limit);
+ if (feedConfig.limit) {
+ posts = posts.limit(feedConfig.limit);
+ }
var xml = template({
config: config,
Sorry, after https://github.com/hexojs/hexo/issues/1494 I gave up on hexo and switched to pelican. I am in the end a Python programmer really, and apparently when desiring rST
one should not play with JavaScript.
The change above is thus now in public domain, and you can do whatever you want to do with it.
Okay. Sorry Hexo didn't work out for you. I'm closing your other PRs then.