hexo-generator-feed icon indicating copy to clipboard operation
hexo-generator-feed copied to clipboard

Generate feeds by categories?

Open kuanyui opened this issue 10 years ago • 11 comments

In addition to the whole website, if it possible to generate separate feeds by different categories? Like WP: http://codex.wordpress.org/WordPress_Feeds

kuanyui avatar Jun 17 '14 16:06 kuanyui

Any update on it?

danielpassos avatar Nov 10 '14 15:11 danielpassos

It seems that somebody have to write one and push the commit by itself if it want...

kuanyui avatar Nov 11 '14 03:11 kuanyui

I would also like to have a feed based on either a category or a tag.

practicalli-johnny avatar Jan 31 '15 22:01 practicalli-johnny

I really want this feature at least for category .

rickyking avatar Mar 31 '15 20:03 rickyking

I found the hexo-generator-category-feed, but don't worked here with Hexo 3.0.1. Any idea?

acfreitas avatar May 06 '15 14:05 acfreitas

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 avatar Jun 03 '15 17:06 zklhp

@zklhp you can add this to the site~

Xuanwo avatar Jun 05 '15 01:06 Xuanwo

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 avatar Jun 21 '15 22:06 mcepl

@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,

leesei avatar Apr 13 '16 08:04 leesei

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.

mcepl avatar Apr 13 '16 11:04 mcepl

Okay. Sorry Hexo didn't work out for you. I'm closing your other PRs then.

leesei avatar Apr 13 '16 14:04 leesei