Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate feeds by categories? #3

Open
kuanyui opened this issue Jun 17, 2014 · 11 comments
Open

Generate feeds by categories? #3

kuanyui opened this issue Jun 17, 2014 · 11 comments

Comments

@kuanyui
Copy link

kuanyui commented Jun 17, 2014

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

@danielpassos
Copy link

Any update on it?

@kuanyui
Copy link
Author

kuanyui commented Nov 11, 2014

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

@practicalli-johnny
Copy link

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

@rickyking
Copy link

I really want this feature at least for category .

@acfreitas
Copy link

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

@zklhp
Copy link

zklhp commented Jun 3, 2015

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.

@Xuanwo
Copy link

Xuanwo commented Jun 5, 2015

@zklhp you can add this to the site~

@mcepl
Copy link

mcepl commented Jun 21, 2015

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?

@leesei
Copy link
Member

leesei commented Apr 13, 2016

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

@mcepl
Copy link

mcepl commented Apr 13, 2016

Sorry, after hexojs/hexo#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.

@leesei
Copy link
Member

leesei commented Apr 13, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants