hexo-generator-feed
Advanced tools
Comparing version 1.2.2 to 2.0.0
10
index.js
/* global hexo */ | ||
'use strict'; | ||
var assign = require('object-assign'); | ||
var pathFn = require('path'); | ||
const pathFn = require('path'); | ||
var config = hexo.config.feed = assign({ | ||
const config = hexo.config.feed = Object.assign({ | ||
type: 'atom', | ||
@@ -13,6 +12,7 @@ limit: 20, | ||
content_limit: 140, | ||
content_limit_delim: '' | ||
content_limit_delim: '', | ||
order_by: '-date' | ||
}, hexo.config.feed); | ||
var type = config.type.toLowerCase(); | ||
const type = config.type.toLowerCase(); | ||
@@ -19,0 +19,0 @@ // Check feed type |
'use strict'; | ||
var nunjucks = require('nunjucks'); | ||
var env = new nunjucks.Environment(); | ||
var pathFn = require('path'); | ||
var fs = require('fs'); | ||
var gravatar = require('hexo/lib/plugins/helper/gravatar'); | ||
const nunjucks = require('nunjucks'); | ||
const env = new nunjucks.Environment(); | ||
const pathFn = require('path'); | ||
const fs = require('fs'); | ||
const gravatar = require('hexo/lib/plugins/helper/gravatar'); // eslint-disable-line node/no-unpublished-require | ||
env.addFilter('uriencode', function(str) { | ||
env.addFilter('uriencode', str => { | ||
return encodeURI(str); | ||
}); | ||
env.addFilter('noControlChars', function(str) { | ||
return str.replace(/[\x00-\x1F\x7F]/g, ''); | ||
env.addFilter('noControlChars', str => { | ||
return str.replace(/[\x00-\x1F\x7F]/g, ''); // eslint-disable-line no-control-regex | ||
}); | ||
var atomTmplSrc = pathFn.join(__dirname, '../atom.xml'); | ||
var atomTmpl = nunjucks.compile(fs.readFileSync(atomTmplSrc, 'utf8'), env); | ||
var rss2TmplSrc = pathFn.join(__dirname, '../rss2.xml'); | ||
var rss2Tmpl = nunjucks.compile(fs.readFileSync(rss2TmplSrc, 'utf8'), env); | ||
const atomTmplSrc = pathFn.join(__dirname, '../atom.xml'); | ||
const atomTmpl = nunjucks.compile(fs.readFileSync(atomTmplSrc, 'utf8'), env); | ||
const rss2TmplSrc = pathFn.join(__dirname, '../rss2.xml'); | ||
const rss2Tmpl = nunjucks.compile(fs.readFileSync(rss2TmplSrc, 'utf8'), env); | ||
module.exports = function(locals) { | ||
var config = this.config; | ||
var feedConfig = config.feed; | ||
var template = feedConfig.type === 'rss2' ? rss2Tmpl : atomTmpl; | ||
const config = this.config; | ||
const feedConfig = config.feed; | ||
const template = feedConfig.type === 'rss2' ? rss2Tmpl : atomTmpl; | ||
var posts = locals.posts.sort('-date'); | ||
posts = posts.filter(function(post) { | ||
let posts = locals.posts.sort(feedConfig.order_by || '-date'); | ||
posts = posts.filter(post => { | ||
return post.draft !== true; | ||
@@ -34,9 +34,10 @@ }); | ||
var url = config.url; | ||
let url = config.url; | ||
if (url[url.length - 1] !== '/') url += '/'; | ||
var icon; | ||
if (config.email) icon = gravatar(config.email); | ||
let icon = ''; | ||
if (feedConfig.icon) icon = url + encodeURI(feedConfig.icon); | ||
else if (config.email) icon = gravatar(config.email); | ||
var xml = template.render({ | ||
const xml = template.render({ | ||
config: config, | ||
@@ -43,0 +44,0 @@ url: url, |
{ | ||
"name": "hexo-generator-feed", | ||
"version": "1.2.2", | ||
"version": "2.0.0", | ||
"description": "Feed generator plugin for Hexo", | ||
@@ -8,5 +8,4 @@ "main": "index", | ||
"eslint": "eslint .", | ||
"jscs": "jscs .", | ||
"test": "mocha test/index.js", | ||
"test-cov": "istanbul cover --print both _mocha -- test/index.js" | ||
"test-cov": "nyc npm run test" | ||
}, | ||
@@ -16,3 +15,10 @@ "directories": { | ||
}, | ||
"files": [ | ||
"lib/", | ||
"atom.xml", | ||
"index.js", | ||
"rss2.xml" | ||
], | ||
"repository": "hexojs/hexo-generator-feed", | ||
"homepage": "https://hexo.io/", | ||
"keywords": [ | ||
@@ -28,20 +34,20 @@ "hexo", | ||
"Abner Chou <hi@abnerchou.me> (http://abnerchou.me)" | ||
], | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
"nunjucks": "^3.0.0", | ||
"object-assign": "^4.1.1" | ||
"nunjucks": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"babel-eslint": "^7.2.3", | ||
"chai": "^3.5.0", | ||
"babel-eslint": "^10.0.1", | ||
"chai": "^4.2.0", | ||
"cheerio": "^0.22.0", | ||
"eslint": "^2.4.0", | ||
"eslint-config-hexo": "^1.0.4", | ||
"eslint": "^6.0.1", | ||
"eslint-config-hexo": "^3.0.0", | ||
"hexo": "^3.3.1", | ||
"istanbul": "^0.4.5", | ||
"jscs": "^3.0.7", | ||
"jscs-preset-hexo": "^1.0.1", | ||
"mocha": "^3.2.0" | ||
"mocha": "^6.0.2", | ||
"nyc": "14.1.1" | ||
}, | ||
"engines": { | ||
"node": ">=8.6.0" | ||
} | ||
} |
# hexo-generator-feed | ||
[![Build Status](https://travis-ci.org/hexojs/hexo-generator-feed.svg?branch=master)](https://travis-ci.org/hexojs/hexo-generator-feed) [![NPM version](https://badge.fury.io/js/hexo-generator-feed.svg)](http://badge.fury.io/js/hexo-generator-feed) [![Coverage Status](https://img.shields.io/coveralls/hexojs/hexo-generator-feed.svg)](https://coveralls.io/r/hexojs/hexo-generator-feed?branch=master) | ||
[![Build Status](https://travis-ci.org/hexojs/hexo-generator-feed.svg?branch=master)](https://travis-ci.org/hexojs/hexo-generator-feed) | ||
[![NPM version](https://badge.fury.io/js/hexo-generator-feed.svg)](https://www.npmjs.com/package/hexo-generator-feed) | ||
[![Coverage Status](https://img.shields.io/coveralls/hexojs/hexo-generator-feed.svg)](https://coveralls.io/r/hexojs/hexo-generator-feed?branch=master) | ||
@@ -18,3 +20,3 @@ Generate Atom 1.0 or RSS 2.0 feed. | ||
In the [front-matter](https://hexo.io/docs/front-matter.html) of your post, you can optionally add a `description` setting to write a summary for the post. Otherwise the summary will default to the excerpt or the first 140 characters of the post. | ||
In the [front-matter](https://hexo.io/docs/front-matter.html) of your post, you can optionally add a `description`, `intro` or `excerpt` setting to write a summary for the post. Otherwise the summary will default to the excerpt or the first 140 characters of the post. | ||
@@ -34,2 +36,4 @@ ## Options | ||
content_limit_delim: ' ' | ||
order_by: -date | ||
icon: icon.png | ||
``` | ||
@@ -44,1 +48,3 @@ | ||
- **content_limit_delim** - (optional) If **content_limit** is used to shorten post contents, only cut at the last occurrence of this delimiter before reaching the character limit. Not used by default. | ||
- **order_by** - Feed order-by. (Default: -date) | ||
- **icon** - (optional) Custom feed icon. Defaults to a gravatar of email specified in the main config. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
10585
1
8
70
0
48
7
- Removedobject-assign@^4.1.1
- Removedobject-assign@4.1.1(transitive)