hexo-generator-feed
Advanced tools
Comparing version 0.0.10 to 0.1.0
129
index.js
@@ -1,99 +0,54 @@ | ||
var extend = hexo.extend, | ||
route = hexo.route, | ||
xml = require('jstoxml'); | ||
var ejs = require('ejs'), | ||
_ = require('lodash'), | ||
path = require('path'), | ||
file = hexo.util.file2; | ||
extend.generator.register(function(locals, render, callback){ | ||
ejs.filters.cdata = function(str){ | ||
return '<![CDATA[' + (str || '') + ']]>'; | ||
}; | ||
var atomTmplSrc = path.join(__dirname, 'atom.ejs'), | ||
atomTmpl = ejs.compile(file.readFileSync(atomTmplSrc)); | ||
var rss2TmplSrc = path.join(__dirname, 'rss2.ejs'), | ||
rss2Tmpl = ejs.compile(file.readFileSync(rss2TmplSrc)); | ||
hexo.extend.generator.register(function(locals, render, callback){ | ||
var config = hexo.config; | ||
var content = [ | ||
{title: '<![CDATA[' + config.title + ']]>'}, | ||
{ | ||
_name: 'link', | ||
_attrs: { | ||
href: config.url + '/atom.xml', | ||
rel: 'self' | ||
} | ||
}, | ||
{ | ||
_name: 'link', | ||
_attrs: { | ||
href: config.url | ||
} | ||
}, | ||
{updated: new Date().toISOString()}, | ||
{id: config.url + '/'}, | ||
{author: | ||
{ | ||
name: '<![CDATA[' + config.author + ']]>' | ||
} | ||
}, | ||
{ | ||
_name: 'generator', | ||
_attrs: { | ||
uri: 'http://zespia.tw/hexo' | ||
}, | ||
_content: 'Hexo' | ||
} | ||
]; | ||
var feedConfig = _.extend({ | ||
type: 'atom', | ||
limit: 20 | ||
}, config.feed); | ||
if (config.email) content[5].author.email = '<![CDATA[' + config.email + ']]>'; | ||
if (config.subtitle) content.splice(1, 0, {subtitle: '<![CDATA[' + config.subtitle + ']]>'}); | ||
// Restrict feed type | ||
if (feedConfig.type !== 'atom' && feedConfig.type !== 'rss2'){ | ||
feedConfig.type = 'atom'; | ||
} | ||
locals.posts.sort('date', -1).limit(20).each(function(item){ | ||
var entry = [ | ||
{ | ||
_name: 'title', | ||
_attrs: { | ||
type: 'html' | ||
}, | ||
_content: '<![CDATA[' + item.title + ']]>' | ||
}, | ||
{ | ||
_name: 'link', | ||
_attrs: { | ||
href: item.permalink | ||
} | ||
}, | ||
{id: item.permalink}, | ||
{published: item.date.toDate().toISOString()}, | ||
{updated: item.updated.toDate().toISOString()}, | ||
{ | ||
_name: 'content', | ||
_attrs: { | ||
type: 'html' | ||
}, | ||
_content: '<![CDATA[' + item.content + ']]>' | ||
}, | ||
]; | ||
// Set default feed path | ||
if (!feedConfig.path){ | ||
feedConfig.path = feedConfig.type + '.xml'; | ||
} | ||
var items = [].concat(item.tags.toArray(), item.categories.toArray()); | ||
// Add extension name if don't have | ||
if (!path.extname(feedConfig.path)){ | ||
feedConfig.path += '.xml'; | ||
} | ||
if (items.length){ | ||
var categories = []; | ||
items.forEach(function(item){ | ||
categories.push({ | ||
_name: 'category', | ||
_attrs: { | ||
scheme: item.permalink, | ||
term: item.name | ||
} | ||
}); | ||
}); | ||
// Determine which template to use | ||
if (feedConfig.type === 'rss2'){ | ||
var template = rss2Tmpl; | ||
} else { | ||
var template = atomTmpl; | ||
} | ||
entry = [].concat(entry, categories); | ||
} | ||
content.push({entry: entry}); | ||
var xml = template({ | ||
config: config, | ||
posts: locals.posts.sort('date', -1).limit(feedConfig.limit), | ||
feed_url: config.root + feedConfig.path | ||
}); | ||
var result = xml.toXML({ | ||
_name: 'feed', | ||
_attrs: { | ||
xmlns: 'http://www.w3.org/2005/Atom' | ||
}, | ||
_content: content | ||
}, {header: true, indent: ' '}); | ||
route.set('atom.xml', result); | ||
hexo.route.set(feedConfig.path, xml); | ||
callback(); | ||
}); |
{ | ||
"name": "hexo-generator-feed", | ||
"version": "0.0.10", | ||
"version": "0.1.0", | ||
"description": "Feed generator plugin for Hexo", | ||
@@ -10,3 +10,3 @@ "main": "index", | ||
}, | ||
"keywords": ["website", "blog", "cms", "framework", "hexo"], | ||
"keywords": ["hexo", "rss", "feed", "atom"], | ||
"author": "Tommy Chen <tommy351@gmail.com> (http://zespia.tw)", | ||
@@ -17,8 +17,6 @@ "license": { | ||
}, | ||
"engines": { | ||
"hexo": ">= 1.0.0" | ||
}, | ||
"dependencies": { | ||
"jstoxml": "*" | ||
"ejs": "0.8.5", | ||
"lodash": "2.4.1" | ||
} | ||
} |
@@ -1,47 +0,20 @@ | ||
# Feed generator plugin for [Hexo] | ||
# Feed generator for [Hexo] | ||
This plugin can generate Atom 1.0. | ||
This plugin can generate Atom 1.0 and RSS 2.0 feed. | ||
## Usage | ||
## Options | ||
### Install | ||
You can configure this plugin in `_config.yml`. | ||
``` | ||
npm install hexo-generator-feed --save | ||
``` | ||
### Enable | ||
Add `hexo-generator-feed` to `plugins` in `_config.yml`. | ||
``` yaml | ||
plugins: | ||
- hexo-generator-feed | ||
feed: | ||
type: atom | ||
path: atom.xml | ||
limit: 20 | ||
``` | ||
### Disable | ||
- **type** - Feed type. (atom/rss2) | ||
- **path** - Feed path. (Default: atom.xml/rss2.xml) | ||
- **limit** - Maximum number of posts in the feed | ||
Remove `hexo-generator-feed` from `plugins` in `_config.yml`. | ||
``` yaml | ||
plugins: | ||
- hexo-generator-feed | ||
``` | ||
### Update | ||
Execute the following command. | ||
``` | ||
npm update | ||
``` | ||
### Uninstall | ||
Execute the following command. Don't forget to disable the plugin before uninstalling. | ||
``` | ||
npm uninstall hexo-generator-feed | ||
``` | ||
[Hexo]: http://zespia.tw/hexo |
Floating dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
4654
6
0
2
42
20
+ Addedejs@0.8.5
+ Addedlodash@2.4.1
+ Addedejs@0.8.5(transitive)
+ Addedlodash@2.4.1(transitive)
- Removedjstoxml@*
- Removedjstoxml@5.0.2(transitive)