@nuxtjs/feed
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -1,5 +0,23 @@ | ||
# Change Log | ||
# Changelog | ||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
## [2.0.0](https://github.com/nuxt-community/feed-module/compare/v1.1.0...v2.0.0) (2020-05-26) | ||
### Breaking Changes | ||
* **generate:** feed output in generate folder ([#43](https://github.com/nuxt-community/feed-module/issues/43)) ([8832f39](https://github.com/nuxt-community/feed-module/commit/8832f39)) | ||
### Features | ||
* generated files log ([#74](https://github.com/nuxt-community/feed-module/issues/74)) ([9aae26c](https://github.com/nuxt-community/feed-module/commit/9aae26c)) | ||
### Tests | ||
* 💍 update rss2 snapshots ([#79](https://github.com/nuxt-community/feed-module/issues/79)) ([d320fb0](https://github.com/nuxt-community/feed-module/commit/d320fb0)) | ||
* refactor tests with module-test-utils ([#80](https://github.com/nuxt-community/feed-module/issues/80)) ([e418c34](https://github.com/nuxt-community/feed-module/commit/e418c34)) | ||
* **module:** explicitly call nuxt.ready() ([#46](https://github.com/nuxt-community/feed-module/issues/46)) ([5ddf6d3](https://github.com/nuxt-community/feed-module/commit/5ddf6d3)) | ||
<a name="1.1.0"></a> | ||
@@ -6,0 +24,0 @@ # [1.1.0](https://github.com/nuxt-community/feed-module/compare/v1.0.0...v1.1.0) (2019-01-12) |
@@ -1,10 +0,8 @@ | ||
import path from 'path' | ||
import fs from 'fs-extra' | ||
import AsyncCache from 'async-cache' | ||
import { promisify } from 'util' | ||
import { Feed } from 'feed' | ||
import consola from 'consola' | ||
const { join, resolve } = require('path') | ||
const { promisify } = require('util') | ||
const { writeFileSync } = require('fs') | ||
const { Feed } = require('feed') | ||
const AsyncCache = require('async-cache') | ||
const logger = require('./logger') | ||
const logger = consola.withScope('nuxt:feed') | ||
const defaults = { | ||
@@ -16,25 +14,11 @@ path: '/feed.xml', | ||
export default async function feed () { | ||
// Factory function | ||
if (typeof this.options.feed === 'function') { | ||
this.options.feed = await this.options.feed() | ||
} | ||
module.exports = async function (moduleOptions) { | ||
const options = [ | ||
...await parseOptions(this.options.feed), | ||
...await parseOptions(moduleOptions) | ||
].map(o => ({ ...defaults, ...o })) | ||
// Factory object | ||
if (!Array.isArray(this.options.feed)) { | ||
if (this.options.feed.factory) { | ||
this.options.feed = await this.options.feed.factory(this.options.feed.data) | ||
} | ||
} | ||
// Single feed | ||
if (!Array.isArray(this.options.feed)) { | ||
this.options.feed = [this.options.feed] | ||
} | ||
const options = Object.assign([], this.options.feed).map(o => Object.assign({}, defaults, o)) | ||
const feedCache = new AsyncCache({ | ||
load (feedIndex, callback) { | ||
createFeed(options[feedIndex], callback).catch(err => /* istanbul ignore next */ logger.error(err)) | ||
createFeed(options[feedIndex], callback).catch(err => logger.error(err)) | ||
} | ||
@@ -46,6 +30,12 @@ }) | ||
options.forEach((feedOptions, index) => { | ||
this.nuxt.hook('generate:before', async () => { | ||
const xmlGeneratePath = path.resolve(this.options.srcDir, path.join('static', feedOptions.path)) | ||
await fs.removeSync(xmlGeneratePath) | ||
await fs.outputFile(xmlGeneratePath, await feedCache.get(index)) | ||
this.nuxt.hook('generate:done', async () => { | ||
if (index === 0) { | ||
logger.info('Generating feeds') | ||
} | ||
const xmlGeneratePath = resolve(this.options.rootDir, join(this.options.generate.dir, feedOptions.path)) | ||
writeFileSync(xmlGeneratePath, await feedCache.get(index)) | ||
logger.success('Generated', feedOptions.path) | ||
}) | ||
@@ -60,3 +50,3 @@ | ||
res.end(xml) | ||
} catch (err) /* istanbul ignore next */ { | ||
} catch (err) { | ||
next(err) | ||
@@ -69,2 +59,28 @@ } | ||
async function parseOptions (options) { | ||
// Factory function | ||
if (typeof options === 'function') { | ||
options = await options() | ||
} | ||
// Factory object | ||
if (!Array.isArray(options)) { | ||
if (options.factory) { | ||
options = await options.factory(options.data) | ||
} | ||
} | ||
// Check if is empty | ||
if (Object.keys(options).length === 0) { | ||
return [] | ||
} | ||
// Single feed | ||
if (!Array.isArray(options)) { | ||
options = [options] | ||
} | ||
return options | ||
} | ||
function resolveContentType (type) { | ||
@@ -86,9 +102,16 @@ const lookup = { | ||
const feed = new Feed() | ||
try { | ||
await feedOptions.create.call(this, feed, feedOptions.data) | ||
feed.options = Object.assign({ generator: 'https://github.com/nuxt-community/feed-module' }, feed.options) | ||
} catch (err) /* istanbul ignore next */ { | ||
feed.options = { | ||
generator: 'https://github.com/nuxt-community/feed-module', | ||
...feed.options | ||
} | ||
} catch (err) { | ||
logger.error(err) | ||
logger.fatal('Error while executing feed creation function') | ||
return callback(null, '', feedOptions.cacheTime) | ||
} | ||
return callback(null, feed[feedOptions.type](), feedOptions.cacheTime) | ||
@@ -95,0 +118,0 @@ } |
{ | ||
"name": "@nuxtjs/feed", | ||
"version": "1.1.0", | ||
"description": "", | ||
"version": "2.0.0", | ||
"description": "Feed module enables everyone to have RSS, Atom and Json.", | ||
"keywords": [ | ||
"nuxtjs", | ||
"nuxt", | ||
"feed", | ||
"blog", | ||
"rss", | ||
"atom", | ||
"json" | ||
], | ||
"license": "MIT", | ||
"contributors": [ | ||
{ | ||
"name": "Alexander Lichter <npm@lichter.io>" | ||
} | ||
"Alexander Lichter <npm@lichter.io>" | ||
], | ||
"main": "lib/module.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/nuxt-community/feed-module" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/nuxt-community/feed-module/issues" | ||
}, | ||
"repository": "nuxt-community/feed-module", | ||
"publishConfig": { | ||
@@ -24,66 +25,26 @@ "access": "public" | ||
"dev": "nuxt test/fixture", | ||
"lint": "eslint lib test", | ||
"test": "yarn lint && yarn jest", | ||
"release": "standard-version && git push --follow-tags && npm publish", | ||
"commitlint": "commitlint -e $GIT_PARAMS", | ||
"coverage": "codecov" | ||
"generate": "nuxt generate test/fixture", | ||
"lint": "eslint --ext .js,.vue lib test", | ||
"test": "yarn lint && jest", | ||
"release": "yarn test && standard-version && git push --follow-tags && npm publish" | ||
}, | ||
"eslintIgnore": [ | ||
"lib/templates/*.*" | ||
], | ||
"files": [ | ||
"lib" | ||
], | ||
"keywords": [ | ||
"nuxtjs", | ||
"nuxt", | ||
"feed", | ||
"blog", | ||
"rss", | ||
"atom", | ||
"json" | ||
], | ||
"engines": { | ||
"node": ">=8.0.0", | ||
"npm": ">=5.0.0" | ||
}, | ||
"jest": { | ||
"testEnvironment": "node", | ||
"collectCoverage": true, | ||
"coveragePathIgnorePatterns": [ | ||
"/node_modules/", | ||
"/test/fixture" | ||
] | ||
}, | ||
"dependencies": { | ||
"async-cache": "^1.1.0", | ||
"consola": "^2.3.2", | ||
"feed": "^2.0.2", | ||
"fs-extra": "^7.0.1" | ||
"consola": "^2.12.1", | ||
"feed": "^4.2.0" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^7.3.1", | ||
"@commitlint/config-conventional": "^7.3.1", | ||
"codecov": "^3.1.0", | ||
"eslint": "^5.12.0", | ||
"eslint-config-standard": "^12.0.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-jest": "^22.1.3", | ||
"eslint-plugin-node": "^8.0.1", | ||
"eslint-plugin-promise": "^4.0.1", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"eslint-plugin-vue": "^5.1.0", | ||
"husky": "^1.3.1", | ||
"jest": "^23.6.0", | ||
"jsdom": "^13.1.0", | ||
"nuxt": "^2.3.4", | ||
"request-promise-native": "^1.0.5", | ||
"standard-version": "^4.4.0" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "npm run lint", | ||
"commit-msg": "npm run commitlint" | ||
} | ||
"@commitlint/cli": "latest", | ||
"@commitlint/config-conventional": "latest", | ||
"@nuxtjs/eslint-config": "latest", | ||
"@nuxtjs/module-test-utils": "latest", | ||
"eslint": "latest", | ||
"husky": "latest", | ||
"jest": "latest", | ||
"nuxt-edge": "latest", | ||
"standard-version": "latest" | ||
} | ||
} |
182
README.md
# Feed module - Everyone deserves RSS, Atom and Json | ||
[![npm (scoped with tag)](https://img.shields.io/npm/v/@nuxtjs/feed/latest.svg?style=flat-square)](https://npmjs.com/package/@nuxtjs/feed) | ||
[![npm](https://img.shields.io/npm/dt/@nuxtjs/feed.svg?style=flat-square)](https://npmjs.com/package/@nuxtjs/feed) | ||
[![Build Status](https://travis-ci.org/nuxt-community/feed-module.svg?branch=master)](https://travis-ci.org/nuxt-community/feed-module) | ||
[![codecov](https://codecov.io/gh/nuxt-community/feed-module/branch/master/graph/badge.svg)](https://codecov.io/gh/nuxt-community/feed-module) | ||
[![Dependencies](https://david-dm.org/nuxt-community/feed-module/status.svg?style=flat-square)](https://david-dm.org/nuxt-community/feed-module) | ||
[![js-standard-style](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com) | ||
> | ||
[![npm version][npm-version-src]][npm-version-href] | ||
[![npm downloads][npm-downloads-src]][npm-downloads-href] | ||
[![Github Actions CI][github-actions-ci-src]][github-actions-ci-href] | ||
[![Codecov][codecov-src]][codecov-href] | ||
[![License][license-src]][license-href] | ||
> Feed module enables everyone to have RSS, Atom and Json. | ||
[📖 **Release Notes**](./CHANGELOG.md) | ||
@@ -15,30 +15,44 @@ | ||
* Three different feed types (RSS 2.0, ATOM 1.0 and JSON 1.0) | ||
* As many feeds as you like! | ||
* Completely customizable. Need to fetch data before? No problem! | ||
* Works with **all modes** (yes, even generate!) | ||
* For Nuxt 2.x and higher | ||
- Three different feed types (RSS 2.0, ATOM 1.0 and JSON 1.0) | ||
- As many feeds as you like! | ||
- Completely customizable. Need to fetch data before? No problem! | ||
- Works with **all modes** (yes, even generate!) | ||
- For Nuxt 2.x and higher | ||
## Setup | ||
- Add `@nuxtjs/feed` dependency using yarn or npm to your project | ||
- Add `@nuxtjs/feed` to `modules` section of `nuxt.config.js` | ||
1. Add `@nuxtjs/feed` dependency to your project | ||
```bash | ||
yarn add @nuxtjs/feed # or npm install @nuxtjs/feed | ||
``` | ||
2. Add `@nuxtjs/feed` to the `modules` section of `nuxt.config.js` | ||
```js | ||
export default { | ||
modules: [ | ||
// Simple usage | ||
'@nuxtjs/feed', | ||
], | ||
feed: [ | ||
// Your feeds here | ||
] | ||
['@nuxtjs/feed', { | ||
// Your feeds here | ||
}] | ||
] | ||
} | ||
``` | ||
- Configure it as you need | ||
### Using top level options | ||
```js | ||
export default { | ||
modules: [ | ||
'@nuxtjs/feed' | ||
], | ||
feed: [ | ||
// Your feeds here | ||
] | ||
} | ||
``` | ||
## Configuration | ||
So.. how to get these feeds working now? | ||
So... how to get these feeds working now? | ||
@@ -49,14 +63,12 @@ ### Configuration object overview | ||
export default { | ||
//... | ||
feed: [ | ||
// A default feed configuration object | ||
{ | ||
path: '/feed.xml', // The route to your feed. | ||
async create (feed) {}, // The create function (see below) | ||
cacheTime: 1000 * 60 * 15, // How long should the feed be cached | ||
type: 'rss2', // Can be: rss2, atom1, json1 | ||
data: ['Some additional data'] //will be passed as 2nd argument to `create` function | ||
} | ||
] | ||
//... | ||
feed: [ | ||
// A default feed configuration object | ||
{ | ||
path: '/feed.xml', // The route to your feed. | ||
async create(feed) {}, // The create function (see below) | ||
cacheTime: 1000 * 60 * 15, // How long should the feed be cached | ||
type: 'rss2', // Can be: rss2, atom1, json1 | ||
data: ['Some additional data'] // Will be passed as 2nd argument to `create` function | ||
} | ||
] | ||
} | ||
@@ -67,3 +79,3 @@ ``` | ||
Let's take a closer look on the `create` function. This is the API that | ||
Let's take a closer look on the `create` function. This is the API that | ||
actually modifies your upcoming feed. | ||
@@ -74,11 +86,10 @@ | ||
```js | ||
//Import axios into your nuxt.config.js | ||
import axios from 'axios' | ||
// In your `feed` array: | ||
async create (feed){ | ||
// In your `feed` array's object: | ||
async create (feed) { | ||
feed.options = { | ||
title: 'My blog', | ||
link: 'https://lichter.io/feed.xml', | ||
description: 'This is my personal feed!', | ||
description: 'This is my personal feed!' | ||
} | ||
@@ -123,34 +134,34 @@ | ||
```js | ||
{ | ||
feed: async () => { | ||
const posts = (await axios.get('https://blog-api.lichter.io/posts')).data | ||
const tags = (await axios.get('https://blog-api.lichter.io/tags')).data | ||
return tags.map(t => { | ||
const relevantPosts = posts.filter(/*filter posts somehow*/) | ||
return { | ||
path: `/${t.slug}.xml`, // The route to your feed. | ||
async create (feed) { | ||
feed.options = { | ||
title: `${t.name} - My blog`, | ||
link: `https://blog.lichter.io/${t.slug}.xml`, | ||
description: `All posts related to ${t.name} of my blog`, | ||
} | ||
relevantPosts.forEach(post => { | ||
feed.addItem({ | ||
title: post.title, | ||
id: post.id, | ||
link: `https://blog.lichter.io/posts/${post.slug}`, | ||
description: post.excerpt, | ||
content: post.text | ||
}) | ||
}) | ||
}, | ||
cacheTime: 1000 * 60 * 15, | ||
type: 'rss2' | ||
} | ||
}) | ||
} | ||
export default { | ||
feed: async () => { | ||
const posts = (await axios.get('https://blog-api.lichter.io/posts')).data | ||
const tags = (await axios.get('https://blog-api.lichter.io/tags')).data | ||
return tags.map(t => { | ||
const relevantPosts = posts.filter(/*filter posts somehow*/) | ||
return { | ||
path: `/${t.slug}.xml`, // The route to your feed. | ||
async create(feed) { | ||
feed.options = { | ||
title: `${t.name} - My blog`, | ||
link: `https://blog.lichter.io/${t.slug}.xml`, | ||
description: `All posts related to ${t.name} of my blog` | ||
} | ||
relevantPosts.forEach(post => { | ||
feed.addItem({ | ||
title: post.title, | ||
id: post.id, | ||
link: `https://blog.lichter.io/posts/${post.slug}`, | ||
description: post.excerpt, | ||
content: post.text | ||
}) | ||
}) | ||
}, | ||
cacheTime: 1000 * 60 * 15, | ||
type: 'rss2' | ||
} | ||
}) | ||
} | ||
} | ||
@@ -162,5 +173,5 @@ ``` | ||
```js | ||
{ | ||
export default { | ||
feed: { | ||
data: ['Your data here'] | ||
data: ['Your data here'], | ||
factory: (dataFromFeedDotData) => {/* your factory function */} | ||
@@ -171,8 +182,7 @@ } | ||
## Development | ||
- Clone this repository | ||
- Install dependencies using `yarn install` or `npm install` | ||
- Start development server using `npm run dev` | ||
1. Clone this repository | ||
2. Install dependencies using `yarn install` or `npm install` | ||
3. Start development server using `npm run dev` | ||
@@ -183,2 +193,18 @@ ## License | ||
Copyright (c) Alexander Lichter | ||
Copyright (c) - Nuxt Community | ||
<!-- Badges --> | ||
[npm-version-src]: https://img.shields.io/npm/v/@nuxtjs/feed/latest.svg | ||
[npm-version-href]: https://npmjs.com/package/@nuxtjs/feed | ||
[npm-downloads-src]: https://img.shields.io/npm/dt/@nuxtjs/feed.svg | ||
[npm-downloads-href]: https://npmjs.com/package/@nuxtjs/feed | ||
[github-actions-ci-src]: https://github.com/nuxt-community/feed-module/workflows/ci/badge.svg | ||
[github-actions-ci-href]: https://github.com/nuxt-community/feed-module/actions?query=workflow%3Aci | ||
[codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/feed-module.svg | ||
[codecov-href]: https://codecov.io/gh/nuxt-community/feed-module | ||
[license-src]: https://img.shields.io/npm/l/@nuxtjs/feed.svg | ||
[license-href]: https://npmjs.com/package/@nuxtjs/feed |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
13601
3
9
6
96
203
1
2
+ Addedfeed@4.2.2(transitive)
+ Addedsax@1.4.1(transitive)
+ Addedxml-js@1.6.11(transitive)
- Removedfs-extra@^7.0.1
- Removedfeed@2.0.4(transitive)
- Removedfs-extra@7.0.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedjsonfile@4.0.0(transitive)
- Removedluxon@1.28.1(transitive)
- Removeduniversalify@0.1.2(transitive)
- Removedxml@1.0.1(transitive)
Updatedconsola@^2.12.1
Updatedfeed@^4.2.0