Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

hexo-generator-feed

Package Overview
Dependencies
45
Maintainers
8
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

lib/autodiscovery.js

61

index.js
/* global hexo */
'use strict';
const pathFn = require('path');
const { extname } = require('path');

@@ -13,24 +13,55 @@ const config = hexo.config.feed = Object.assign({

content_limit_delim: '',
order_by: '-date'
order_by: '-date',
autodiscovery: true
}, hexo.config.feed);
const type = config.type.toLowerCase();
let type = config.type;
let path = config.path;
const feedFn = require('./lib/generator');
// Check feed type
if (type !== 'atom' && type !== 'rss2') {
config.type = 'atom';
} else {
config.type = type;
if (typeof type === 'string') type = [type];
if (!type || !Array.isArray(type)) {
type = ['atom'];
}
// Set default feed path
if (!config.path) {
config.path = config.type + '.xml';
if (Array.isArray(type) && type.length > 2) {
type = type.slice(0, 2);
}
// Add extension name if don't have
if (!pathFn.extname(config.path)) {
config.path += '.xml';
type = type.map((str, i) => {
str = str.toLowerCase();
if (str !== 'atom' && str !== 'rss2') {
if (i === 0) str = 'atom';
else str = 'rss2';
}
return str;
});
if (!path || typeof path === 'string' || !Array.isArray(path)) {
path = type.map(str => str.concat('.xml'));
}
hexo.extend.generator.register('feed', require('./lib/generator'));
if (Array.isArray(path) && path.length > 2) {
path = path.slice(0, 2);
}
path = path.map(str => {
if (!extname(str)) return str.concat('.xml');
return str;
});
config.type = type;
config.path = path;
for (const feedType of type) {
hexo.extend.generator.register(feedType, locals => {
return feedFn.call(hexo, locals, feedType, path[type.indexOf(feedType)]);
});
}
if (typeof config.autodiscovery === 'undefined') config.autodiscovery = true;
if (config.autodiscovery === true) {
hexo.extend.filter.register('after_render:html', require('./lib/autodiscovery'));
}

@@ -5,8 +5,8 @@ 'use strict';

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
const { join } = require('path');
const { readFileSync } = require('fs');
const { encodeURL, gravatar, full_url_for } = require('hexo-util');
env.addFilter('uriencode', str => {
return encodeURI(str);
return encodeURL(str);
});

@@ -18,11 +18,11 @@

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);
const atomTmplSrc = join(__dirname, '../atom.xml');
const atomTmpl = nunjucks.compile(readFileSync(atomTmplSrc, 'utf8'), env);
const rss2TmplSrc = join(__dirname, '../rss2.xml');
const rss2Tmpl = nunjucks.compile(readFileSync(rss2TmplSrc, 'utf8'), env);
module.exports = function(locals) {
module.exports = function(locals, type, path) {
const config = this.config;
const feedConfig = config.feed;
const template = feedConfig.type === 'rss2' ? rss2Tmpl : atomTmpl;
const template = type === 'atom' ? atomTmpl : rss2Tmpl;

@@ -40,17 +40,17 @@ let posts = locals.posts.sort(feedConfig.order_by || '-date');

let icon = '';
if (feedConfig.icon) icon = url + encodeURI(feedConfig.icon);
if (feedConfig.icon) icon = full_url_for.call(this, feedConfig.icon);
else if (config.email) icon = gravatar(config.email);
const xml = template.render({
config: config,
url: url,
icon: icon,
posts: posts,
feed_url: config.root + feedConfig.path
config,
url,
icon,
posts,
feed_url: config.root + path
});
return {
path: feedConfig.path,
path,
data: xml
};
};
{
"name": "hexo-generator-feed",
"version": "2.0.0",
"version": "2.1.0",
"description": "Feed generator plugin for Hexo",

@@ -35,2 +35,3 @@ "main": "index",

"dependencies": {
"hexo-util": "^1.3.0",
"nunjucks": "^3.0.0"

@@ -44,3 +45,3 @@ },

"eslint-config-hexo": "^3.0.0",
"hexo": "^3.3.1",
"hexo": "^4.0.0",
"mocha": "^6.0.2",

@@ -50,4 +51,4 @@ "nyc": "14.1.1"

"engines": {
"node": ">=8.6.0"
"node": ">=8.10.0"
}
}

@@ -37,6 +37,21 @@ # hexo-generator-feed

icon: icon.png
autodiscovery: true
```
- **type** - Feed type. (atom/rss2)
- **path** - Feed path. (Default: atom.xml/rss2.xml)
- **type** - Feed type. `atom` or `rss2`. Specify `['atom', 'rss2']` to output both types. (Default: `atom`)
* Example:
``` yaml
feed:
# Generate atom feed
type: atom
# Generate both atom and rss2 feeds
type:
- atom
- rss2
path:
- atom.xml
- rss2.xml
```
- **path** - Feed path. When both types are specified, path must follow the order of type value. (Default: atom.xml/rss2.xml)
- **limit** - Maximum number of posts in the feed (Use `0` or `false` to show all posts)

@@ -49,1 +64,3 @@ - **hub** - URL of the PubSubHubbub hubs (Leave it empty if you don't use it)

- **icon** - (optional) Custom feed icon. Defaults to a gravatar of email specified in the main config.
- **autodiscovery** - Add feed [autodiscovery](http://www.rssboard.org/rss-autodiscovery). (Default: `true`)
* Many themes already offer this feature, so you may also need to adjust the theme's config if you wish to disable it.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc