diff --git a/docs/config/README.md b/docs/config/README.md index 68d6116..60f870b 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -249,4 +249,18 @@ It will be enabled when `endpoint` is provided. e.g. ``` [vuepress-plugin-mailchimp](https://vuepress-plugin-mailchimp.billyyyyy3320.com/) is how we implement the feature. This config will be pass directly to it, so please head [vuepress-plugin-mailchimp](https://vuepress-plugin-mailchimp.billyyyyy3320.com/#config) for more details. +## feed +- Type: `object` +- Default: `{}` +- Required: `false` + +It will be enabled when `canonical_base` is provided. e.g. + +```js +{ + canonical_base: 'https://yoursite' +} +``` + +All the generated files will be placed under your output directory. If you wish to make further configuration, please check out [vuepress-plugin-feed](https://github.com/webmasterish/vuepress-plugin-feed). diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.md index ff8b37a..f33d19b 100644 --- a/docs/guide/getting-started.md +++ b/docs/guide/getting-started.md @@ -460,6 +460,29 @@ In your theme, You'll probably offer users options whether to enable or not. You Please head [UI-customization](https://vuepress-plugin-mailchimp.billyyyyy3320.com/#ui-customization) if you don't like the default UI. +## Feed + +Feed is another approach to allow your users to get your latest content. RSS, Atom, and even JSON feeds are the right tools for the job. Let's see an example: + +```JavaScript +// .vuepress/config.js +module.exports = { + plugins: [ + [ + '@vuepress/blog', + { + feed: { + canonical_base: 'http://yoursite', + }, + }, + ], + ], +} +``` + +After building, you'll be able to find them (`rss.xml`, `feed.atom`, `feed.json`) in you output directory (`dist`). + + ## Examples There're some [examples](https://github.com/vuepressjs/vuepress-plugin-blog/tree/master/examples) under this project help us test this plugin. They're also simplest examples for you after reading all the concept above. diff --git a/examples/sitemap/.vuepress/config.js b/examples/sitemap+feed/.vuepress/config.js similarity index 89% rename from examples/sitemap/.vuepress/config.js rename to examples/sitemap+feed/.vuepress/config.js index a7400b3..e3b7248 100644 --- a/examples/sitemap/.vuepress/config.js +++ b/examples/sitemap+feed/.vuepress/config.js @@ -26,6 +26,9 @@ module.exports = { sitemap: { hostname: 'https://yourdomain' }, + feed:{ + canonical_base: 'http://localhost:8080', + } }], ], } diff --git a/examples/sitemap/.vuepress/theme/layouts/FrontmatterKey.vue b/examples/sitemap+feed/.vuepress/theme/layouts/FrontmatterKey.vue similarity index 100% rename from examples/sitemap/.vuepress/theme/layouts/FrontmatterKey.vue rename to examples/sitemap+feed/.vuepress/theme/layouts/FrontmatterKey.vue diff --git a/examples/sitemap/.vuepress/theme/layouts/GlobalLayout.vue b/examples/sitemap+feed/.vuepress/theme/layouts/GlobalLayout.vue similarity index 100% rename from examples/sitemap/.vuepress/theme/layouts/GlobalLayout.vue rename to examples/sitemap+feed/.vuepress/theme/layouts/GlobalLayout.vue diff --git a/examples/sitemap/.vuepress/theme/layouts/Layout.vue b/examples/sitemap+feed/.vuepress/theme/layouts/Layout.vue similarity index 100% rename from examples/sitemap/.vuepress/theme/layouts/Layout.vue rename to examples/sitemap+feed/.vuepress/theme/layouts/Layout.vue diff --git a/examples/sitemap/.vuepress/theme/layouts/Post.vue b/examples/sitemap+feed/.vuepress/theme/layouts/Post.vue similarity index 100% rename from examples/sitemap/.vuepress/theme/layouts/Post.vue rename to examples/sitemap+feed/.vuepress/theme/layouts/Post.vue diff --git a/examples/sitemap/_posts/2018-11-7-frontmatter-in-vuepress.md b/examples/sitemap+feed/_posts/2018-11-7-frontmatter-in-vuepress.md similarity index 100% rename from examples/sitemap/_posts/2018-11-7-frontmatter-in-vuepress.md rename to examples/sitemap+feed/_posts/2018-11-7-frontmatter-in-vuepress.md diff --git a/examples/sitemap/_posts/2019-2-26-markdown-slot.md b/examples/sitemap+feed/_posts/2019-2-26-markdown-slot.md similarity index 100% rename from examples/sitemap/_posts/2019-2-26-markdown-slot.md rename to examples/sitemap+feed/_posts/2019-2-26-markdown-slot.md diff --git a/examples/sitemap/_posts/2019-5-16-writing-a-vuepress-theme-4.md b/examples/sitemap+feed/_posts/2019-5-16-writing-a-vuepress-theme-4.md similarity index 100% rename from examples/sitemap/_posts/2019-5-16-writing-a-vuepress-theme-4.md rename to examples/sitemap+feed/_posts/2019-5-16-writing-a-vuepress-theme-4.md diff --git a/examples/sitemap/_posts/2019-8-15-why-I-like-git-rebase.md b/examples/sitemap+feed/_posts/2019-8-15-why-I-like-git-rebase.md similarity index 100% rename from examples/sitemap/_posts/2019-8-15-why-I-like-git-rebase.md rename to examples/sitemap+feed/_posts/2019-8-15-why-I-like-git-rebase.md diff --git a/examples/sitemap/_posts/2019-9-8-dive-into-vuepress-with-plugin-apis.md b/examples/sitemap+feed/_posts/2019-9-8-dive-into-vuepress-with-plugin-apis.md similarity index 100% rename from examples/sitemap/_posts/2019-9-8-dive-into-vuepress-with-plugin-apis.md rename to examples/sitemap+feed/_posts/2019-9-8-dive-into-vuepress-with-plugin-apis.md diff --git a/package.json b/package.json index f1a3a58..d7e879f 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "dayjs": "^1.8.19", "vuejs-paginate": "^2.1.0", "vuepress-plugin-disqus": "^0.2.0", + "vuepress-plugin-feed": "^0.1.8", "vuepress-plugin-mailchimp": "^1.4.1", "vuepress-plugin-sitemap": "^2.3.1" }, diff --git a/src/node/handleOptions.ts b/src/node/handleOptions.ts index f2cbdcc..bf28b5b 100644 --- a/src/node/handleOptions.ts +++ b/src/node/handleOptions.ts @@ -233,11 +233,23 @@ export function handleOptions( } } - if (!!(options.newsletter && options.newsletter.endpoint)) { + if (options.newsletter && options.newsletter.endpoint) { plugins.push(['vuepress-plugin-mailchimp', options.newsletter]); services.email.enabled = true; } + if (options.feed && options.feed.canonical_base) { + /* eslint-disable @typescript-eslint/camelcase */ + const defaultFeedOptions = { + posts_directories: [] as string[], + }; + directories.forEach(dir => { + defaultFeedOptions.posts_directories.push(dir.dirname); + }); + const feedOptions = Object.assign({}, defaultFeedOptions, options.feed); + plugins.push(['vuepress-plugin-feed', feedOptions]); + } + const processedData = { pageEnhancers, frontmatterClassificationPages, diff --git a/src/node/interface/Options.ts b/src/node/interface/Options.ts index c63ebf6..2681626 100644 --- a/src/node/interface/Options.ts +++ b/src/node/interface/Options.ts @@ -158,6 +158,7 @@ export interface BlogPluginOptions { globalPagination: PaginationConfig; //TODO: define types sitemap: any; + feed: any; comment: Comment; newsletter: Newsletter; } diff --git a/yarn.lock b/yarn.lock index 3c08ced..135cccf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3987,6 +3987,14 @@ faye-websocket@~0.11.1: dependencies: websocket-driver ">=0.5.1" +feed@2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/feed/-/feed-2.0.4.tgz#14cd71b3bae1e965b81f7e0c5927e8941de996f8" + integrity sha512-sWatfulDP6d18qVaWcu34qmq9ml6UeN6nHSBJpNZ2muBqxjPAdT375whPYAHP+gqLfyabtYU5qf2Dv4nqtlp0w== + dependencies: + luxon "^1.3.3" + xml "^1.0.1" + figgy-pudding@^3.5.1: version "3.5.1" resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.5.1.tgz#862470112901c727a0e495a80744bd5baa1d6790" @@ -5879,6 +5887,16 @@ lodash.debounce@^4.0.8: resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af" integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168= +lodash.defaultsdeep@4.6.1: + version "4.6.1" + resolved "https://registry.yarnpkg.com/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.1.tgz#512e9bd721d272d94e3d3a63653fa17516741ca6" + integrity sha512-3j8wdDzYuWO3lM3Reg03MuQR957t287Rpcxp1njpEa8oDrikb+FwGdW3n+FELh/A6qib6yPit0j/pv9G/yeAqA== + +lodash.isempty@4.4.0: + version "4.4.0" + resolved "https://registry.yarnpkg.com/lodash.isempty/-/lodash.isempty-4.4.0.tgz#6f86cbedd8be4ec987be9aaf33c9684db1b31e7e" + integrity sha1-b4bL7di+TsmHvpqvM8loTbGzHn4= + lodash.ismatch@^4.4.0: version "4.4.0" resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37" @@ -5919,6 +5937,16 @@ lodash.templatesettings@^4.0.0: dependencies: lodash._reinterpolate "^3.0.0" +lodash.trimend@^4.5.1: + version "4.5.1" + resolved "https://registry.yarnpkg.com/lodash.trimend/-/lodash.trimend-4.5.1.tgz#12804437286b98cad8996b79414e11300114082f" + integrity sha1-EoBENyhrmMrYmWt5QU4RMAEUCC8= + +lodash.trimstart@^4.5.1: + version "4.5.1" + resolved "https://registry.yarnpkg.com/lodash.trimstart/-/lodash.trimstart-4.5.1.tgz#8ff4dec532d82486af59573c39445914e944a7f1" + integrity sha1-j/TexTLYJIavWVc8OURZFOlEp/E= + lodash.unescape@4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c" @@ -6002,6 +6030,11 @@ lru-cache@^5.1.1: dependencies: yallist "^3.0.2" +luxon@^1.3.3: + version "1.21.3" + resolved "https://registry.yarnpkg.com/luxon/-/luxon-1.21.3.tgz#f1d5c2a7e855d039836cf4954f883ecac8fc4727" + integrity sha512-lLRwNcNnkZLuv13A1FUuZRZmTWF7ro2ricYvb0L9cvBYHPvZhQdKwrYnZzi103D2XKmlVmxWpdn2wfIiOt2YEw== + make-dir@^1.0.0: version "1.3.0" resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.3.0.tgz#79c1033b80515bd6d24ec9933e860ca75ee27f0c" @@ -8096,6 +8129,11 @@ relateurl@0.2.x: resolved "https://registry.yarnpkg.com/relateurl/-/relateurl-0.2.7.tgz#54dbf377e51440aca90a4cd274600d3ff2d888a9" integrity sha1-VNvzd+UUQKypCkzSdGANP/LYiKk= +remove-markdown@0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/remove-markdown/-/remove-markdown-0.3.0.tgz#5e4b667493a93579728f3d52ecc1db9ca505dc98" + integrity sha1-XktmdJOpNXlyjz1S7MHbnKUF3Jg= + remove-trailing-separator@^1.0.1: version "1.1.0" resolved "https://registry.yarnpkg.com/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz#c24bce2a283adad5bc3f58e0d48249b92379d8ef" @@ -9028,6 +9066,11 @@ strip-json-comments@~2.0.1: resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo= +striptags@3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/striptags/-/striptags-3.1.1.tgz#c8c3e7fdd6fb4bb3a32a3b752e5b5e3e38093ebd" + integrity sha1-yMPn/db7S7OjKjt1LltePjgJPr0= + stylehacks@^4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/stylehacks/-/stylehacks-4.0.3.tgz#6718fcaf4d1e07d8a1318690881e8d96726a71d5" @@ -9857,6 +9900,19 @@ vuepress-plugin-disqus@^0.2.0: dependencies: vue-disqus "^3.0.5" +vuepress-plugin-feed@^0.1.8: + version "0.1.8" + resolved "https://registry.yarnpkg.com/vuepress-plugin-feed/-/vuepress-plugin-feed-0.1.8.tgz#134c69f98c71994d17f926e3c7c2ad006f573195" + integrity sha512-ZDJ2KTAxdeXiykBKOWTht4qleImaY9OEbm9cqQdc/54j0P45ax1PhJjsq5aTs3GcIE1nbZKLCd4fSzhRY6bijg== + dependencies: + feed "2.0.4" + lodash.defaultsdeep "4.6.1" + lodash.isempty "4.4.0" + lodash.trimend "^4.5.1" + lodash.trimstart "^4.5.1" + remove-markdown "0.3.0" + striptags "3.1.1" + vuepress-plugin-mailchimp@^1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/vuepress-plugin-mailchimp/-/vuepress-plugin-mailchimp-1.4.1.tgz#458c4a65f633b0690acd650400e3af6769c947f2" @@ -10171,6 +10227,11 @@ xdg-basedir@^3.0.0: resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-3.0.0.tgz#496b2cc109eca8dbacfe2dc72b603c17c5870ad4" integrity sha1-SWsswQnsqNus/i3HK2A8F8WHCtQ= +xml@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5" + integrity sha1-eLpyAgApxbyHuKgaPPzXS0ovweU= + xmlbuilder@^13.0.0: version "13.0.2" resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-13.0.2.tgz#02ae33614b6a047d1c32b5389c1fdacb2bce47a7"