├── .editorconfig
├── .gitignore
├── README.MD
├── index.js
├── package.json
└── yarn.lock
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = space
5 | indent_size = 2
6 | end_of_line = lf
7 | charset = utf-8
8 | trim_trailing_whitespace = false
9 | insert_final_newline = false
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/node,code
3 |
4 | ### Code ###
5 | # Visual Studio Code - https://code.visualstudio.com/
6 | .settings/
7 | .vscode/
8 | tsconfig.json
9 | jsconfig.json
10 |
11 | ### Node ###
12 | # Logs
13 | logs
14 | *.log
15 | npm-debug.log*
16 | yarn-debug.log*
17 | yarn-error.log*
18 |
19 | # Runtime data
20 | pids
21 | *.pid
22 | *.seed
23 | *.pid.lock
24 |
25 | # Directory for instrumented libs generated by jscoverage/JSCover
26 | lib-cov
27 |
28 | # Coverage directory used by tools like istanbul
29 | coverage
30 |
31 | # nyc test coverage
32 | .nyc_output
33 |
34 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
35 | .grunt
36 |
37 | # Bower dependency directory (https://bower.io/)
38 | bower_components
39 |
40 | # node-waf configuration
41 | .lock-wscript
42 |
43 | # Compiled binary addons (http://nodejs.org/api/addons.html)
44 | build/Release
45 |
46 | # Dependency directories
47 | node_modules/
48 | jspm_packages/
49 |
50 | # Typescript v1 declaration files
51 | typings/
52 |
53 | # Optional npm cache directory
54 | .npm
55 |
56 | # Optional eslint cache
57 | .eslintcache
58 |
59 | # Optional REPL history
60 | .node_repl_history
61 |
62 | # Output of 'npm pack'
63 | *.tgz
64 |
65 | # Yarn Integrity file
66 | .yarn-integrity
67 |
68 | # dotenv environment variables file
69 | .env
70 |
71 |
72 |
73 | # End of https://www.gitignore.io/api/node,code
--------------------------------------------------------------------------------
/README.MD:
--------------------------------------------------------------------------------
1 | # Vuepress Plugin RSS
2 |
3 |
4 |
5 |
6 | > RSS Plugin for Vuepress
7 |
8 | ## Install
9 |
10 | ```
11 | > yarn add vuepress-plugin-rss -D
12 | # or
13 | > npm i vuepress-plugin-rss -D
14 | ```
15 |
16 | ## Config for your site
17 |
18 | - Update your `.vuepress/config.js`
19 |
20 | ```js
21 | module.exports = {
22 | ...
23 | plugins: [
24 | [
25 | 'vuepress-plugin-rss',
26 | {
27 | base_url: '/', // required
28 | site_url: 'https://procollab.com', // required
29 | copyright: '2018 Young Tailors', // optional
30 | // filter some post
31 | filter: (frontmatter) => { return [true|false] },
32 | // How much articles
33 | count: 20
34 | }
35 | ]
36 | ]
37 | }
38 | ```
39 |
40 | ## Contributors
41 |
42 | - Core Plugin - [dacsang97](https://github.com/dacsang97)
43 | - Support Vuepress 1.0 - [tomieric](https://github.com/tomieric)
44 |
45 | ---
46 |
47 | License MIT
48 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const path = require('path')
2 | const RSS = require('rss')
3 | const chalk = require('chalk')
4 |
5 | module.exports = (pluginOptions, ctx) => {
6 | return {
7 | name: 'rss',
8 |
9 | generated () {
10 | const fs = require('fs-extra')
11 | const { pages, sourceDir } = ctx
12 | const { filter = () => true, count = 20 } = pluginOptions
13 | const siteData = require(path.resolve(sourceDir, '.vuepress/config.js'))
14 |
15 | const feed = new RSS({
16 | title: siteData.title,
17 | description: siteData.description,
18 | feed_url: `${pluginOptions.site_url}/rss.xml`,
19 | site_url: `${pluginOptions.site_url}`,
20 | copyright: `${pluginOptions.copyright ? pluginOptions.copyright : 'Coralo 2018'}`,
21 | language: 'en',
22 | })
23 |
24 | pages
25 | .filter(page => String(page.frontmatter.type).toLowerCase() === 'post')
26 | .filter(page => filter(page.frontmatter))
27 | .map(page => ({...page, date: new Date(page.frontmatter.date || '')}))
28 | .sort((a, b) => b.date - a.date)
29 | .map(page => ({
30 | title: page.frontmatter.title,
31 | description: page.excerpt,
32 | url: `${pluginOptions.site_url}${page.path}`,
33 | date: page.date,
34 | }))
35 | .slice(0, count)
36 | .forEach(page => feed.item(page))
37 |
38 | fs.writeFile(
39 | path.resolve(ctx.outDir, 'rss.xml'),
40 | feed.xml()
41 | );
42 | console.log(chalk.green.bold('RSS has been generated!'))
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vuepress-plugin-rss",
3 | "version": "2.0.0",
4 | "main": "index.js",
5 | "author": "SangND",
6 | "repository": "https://github.com/dacsang97/vuepress-plugin-rss.git",
7 | "license": "MIT",
8 | "dependencies": {
9 | "chalk": "^2.4.1",
10 | "fs-extra": "^5.0.0",
11 | "rss": "^1.2.2"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/yarn.lock:
--------------------------------------------------------------------------------
1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2 | # yarn lockfile v1
3 |
4 |
5 | ansi-styles@^3.2.1:
6 | version "3.2.1"
7 | resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
8 | dependencies:
9 | color-convert "^1.9.0"
10 |
11 | chalk@^2.4.1:
12 | version "2.4.1"
13 | resolved "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e"
14 | dependencies:
15 | ansi-styles "^3.2.1"
16 | escape-string-regexp "^1.0.5"
17 | supports-color "^5.3.0"
18 |
19 | color-convert@^1.9.0:
20 | version "1.9.3"
21 | resolved "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
22 | dependencies:
23 | color-name "1.1.3"
24 |
25 | color-name@1.1.3:
26 | version "1.1.3"
27 | resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
28 |
29 | escape-string-regexp@^1.0.5:
30 | version "1.0.5"
31 | resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
32 |
33 | fs-extra@^5.0.0:
34 | version "5.0.0"
35 | resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd"
36 | dependencies:
37 | graceful-fs "^4.1.2"
38 | jsonfile "^4.0.0"
39 | universalify "^0.1.0"
40 |
41 | graceful-fs@^4.1.2, graceful-fs@^4.1.6:
42 | version "4.1.11"
43 | resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
44 |
45 | has-flag@^3.0.0:
46 | version "3.0.0"
47 | resolved "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
48 |
49 | jsonfile@^4.0.0:
50 | version "4.0.0"
51 | resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
52 | optionalDependencies:
53 | graceful-fs "^4.1.6"
54 |
55 | mime-db@~1.25.0:
56 | version "1.25.0"
57 | resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.25.0.tgz#c18dbd7c73a5dbf6f44a024dc0d165a1e7b1c392"
58 |
59 | mime-types@2.1.13:
60 | version "2.1.13"
61 | resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.13.tgz#e07aaa9c6c6b9a7ca3012c69003ad25a39e92a88"
62 | dependencies:
63 | mime-db "~1.25.0"
64 |
65 | rss@^1.2.2:
66 | version "1.2.2"
67 | resolved "https://registry.yarnpkg.com/rss/-/rss-1.2.2.tgz#50a1698876138133a74f9a05d2bdc8db8d27a921"
68 | dependencies:
69 | mime-types "2.1.13"
70 | xml "1.0.1"
71 |
72 | supports-color@^5.3.0:
73 | version "5.5.0"
74 | resolved "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
75 | dependencies:
76 | has-flag "^3.0.0"
77 |
78 | universalify@^0.1.0:
79 | version "0.1.1"
80 | resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"
81 |
82 | xml@1.0.1:
83 | version "1.0.1"
84 | resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5"
85 |
--------------------------------------------------------------------------------