hexo-generator-feed
Advanced tools
Comparing version 2.2.0 to 3.0.0
@@ -6,3 +6,3 @@ /* global hexo */ | ||
const config = hexo.config.feed = Object.assign({ | ||
hexo.config.feed = Object.assign({ | ||
type: 'atom', | ||
@@ -19,2 +19,4 @@ limit: 20, | ||
const config = hexo.config.feed; | ||
let type = config.type; | ||
@@ -21,0 +23,0 @@ let path = config.path; |
@@ -23,5 +23,5 @@ 'use strict'; | ||
return data.replace(/<head>(?!<\/head>).+?<\/head>/s, (str) => str.replace('</head>', `${autodiscoveryTag}</head>`)); | ||
return data.replace(/<head>(?!<\/head>).+?<\/head>/s, str => str.replace('</head>', `${autodiscoveryTag}</head>`)); | ||
} | ||
module.exports = autodiscoveryInject; |
@@ -18,13 +18,18 @@ 'use strict'; | ||
module.exports = function(locals, type, path) { | ||
const config = this.config; | ||
const feedConfig = config.feed; | ||
const { config } = this; | ||
const { email, feed, url: urlCfg } = config; | ||
const { icon: iconCfg, limit, order_by, template: templateCfg, type: typeCfg } = feed; | ||
env.addFilter('formatUrl', str => { | ||
return full_url_for.call(this, str); | ||
}); | ||
let tmplSrc = join(__dirname, `../${type}.xml`); | ||
if (feedConfig.template) { | ||
if (typeof feedConfig.template === 'string') tmplSrc = feedConfig.template; | ||
else tmplSrc = feedConfig.template[feedConfig.type.indexOf(type)]; | ||
if (templateCfg) { | ||
if (typeof templateCfg === 'string') tmplSrc = templateCfg; | ||
else tmplSrc = templateCfg[typeCfg.indexOf(type)]; | ||
} | ||
const template = nunjucks.compile(readFileSync(tmplSrc, 'utf8'), env); | ||
let posts = locals.posts.sort(feedConfig.order_by || '-date'); | ||
let posts = locals.posts.sort(order_by || '-date'); | ||
posts = posts.filter(post => { | ||
@@ -35,16 +40,18 @@ return post.draft !== true; | ||
if (posts.length <= 0) { | ||
feedConfig.autodiscovery = false; | ||
feed.autodiscovery = false; | ||
return; | ||
} | ||
if (feedConfig.limit) posts = posts.limit(feedConfig.limit); | ||
if (limit) posts = posts.limit(limit); | ||
let url = config.url; | ||
let url = urlCfg; | ||
if (url[url.length - 1] !== '/') url += '/'; | ||
let icon = ''; | ||
if (feedConfig.icon) icon = full_url_for.call(this, feedConfig.icon); | ||
else if (config.email) icon = gravatar(config.email); | ||
if (iconCfg) icon = full_url_for.call(this, iconCfg); | ||
else if (email) icon = gravatar(email); | ||
const xml = template.render({ | ||
const feed_url = full_url_for.call(this, path); | ||
const data = template.render({ | ||
config, | ||
@@ -54,3 +61,3 @@ url, | ||
posts, | ||
feed_url: config.root + path | ||
feed_url | ||
}); | ||
@@ -60,4 +67,4 @@ | ||
path, | ||
data: xml | ||
data | ||
}; | ||
}; |
{ | ||
"name": "hexo-generator-feed", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "Feed generator plugin for Hexo", | ||
@@ -35,3 +35,3 @@ "main": "index", | ||
"dependencies": { | ||
"hexo-util": "^1.3.0", | ||
"hexo-util": "^2.1.0", | ||
"nunjucks": "^3.0.0" | ||
@@ -41,13 +41,14 @@ }, | ||
"babel-eslint": "^10.0.1", | ||
"camaro": "^5.0.0", | ||
"chai": "^4.2.0", | ||
"cheerio": "^0.22.0", | ||
"eslint": "^6.0.1", | ||
"eslint-config-hexo": "^3.0.0", | ||
"hexo": "^4.0.0", | ||
"mocha": "^6.0.2", | ||
"nyc": "14.1.1" | ||
"eslint": "^7.0.0", | ||
"eslint-config-hexo": "^4.1.0", | ||
"hexo": "^5.0.0", | ||
"mocha": "^8.0.1", | ||
"nyc": "^15.1.0" | ||
}, | ||
"engines": { | ||
"node": ">=8.10.0" | ||
"node": ">=10.13.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
15893
162
9
+ Addedentities@3.0.1(transitive)
+ Addedhexo-util@2.7.0(transitive)
+ Addedhighlight.js@11.9.0(transitive)
+ Addedhtmlparser2@7.2.0(transitive)
- Removeddomhandler@3.3.0(transitive)
- Removedhexo-util@1.9.1(transitive)
- Removedhighlight.js@9.18.5(transitive)
- Removedhtmlparser2@4.1.0(transitive)
- Removedpunycode.js@2.3.1(transitive)
- Removedstriptags@3.2.0(transitive)
Updatedhexo-util@^2.1.0