From ef648c0ad5c8019ac1056d372af7ba4cbcc8ec15 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Fri, 26 Jun 2020 17:03:23 +0200 Subject: [PATCH] feat: plugins compatibility (#183) * feat(lib): backwards compatibility with `plugins` and `basePlugins` * docs: update for v1.4.0 instead of v2.0.0 --- docs/content/en/changelog.md | 22 ---------------------- docs/content/en/configuration.md | 18 +++++++++++++++--- docs/content/en/displaying.md | 2 +- docs/content/en/fetching.md | 6 +++--- docs/content/en/writing.md | 2 +- docs/content/ja/changelog.md | 21 --------------------- docs/content/ru/changelog.md | 22 ---------------------- lib/index.js | 23 +++++++++++++++++++++++ 8 files changed, 43 insertions(+), 73 deletions(-) delete mode 100644 docs/content/en/changelog.md delete mode 100644 docs/content/ja/changelog.md delete mode 100644 docs/content/ru/changelog.md diff --git a/docs/content/en/changelog.md b/docs/content/en/changelog.md deleted file mode 100644 index a02a711e5..000000000 --- a/docs/content/en/changelog.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: Changelog -description: 'Learn the changes made of the different versions of @nuxt/content module.' -position: 8 -category: Getting started ---- - -## v2.0.0 - -### Markdown plugins - - - markdown.basePlugins and markdown.plugins have been removed in favor of markdown.remarkPlugins and markdown.rehypePlugins. - - -- In development, you can now [live edit](/displaying#live-editing) your content -- Overriding plugins options can still be done but with prefixing by `remark` or `rehype`, for examps `externalLinks` becomes `remarkExternalLinks`. -- You can now override all plugins or append a new plugin using `remarkPlugins` / `rehypePlugins`. -- You can use local plugins using `~/plugins/remark-plugin.js`. -- You can register and configure plugins on the same line like `['remark-plugin', { option: 1 }]`. - -Everything is documented in [this section](/configuration#markdown). diff --git a/docs/content/en/configuration.md b/docs/content/en/configuration.md index b8bc60e34..249bc025b 100644 --- a/docs/content/en/configuration.md +++ b/docs/content/en/configuration.md @@ -76,7 +76,7 @@ content: { - Type `Array` - Default: `[]` -- Version: **v1.3.0** +- Version: **>= v1.3.0** Register nested properties to handle dot-notation and deep filtering. @@ -199,7 +199,7 @@ export default { - Type: `Array` - Default: `['remark-squeeze-paragraphs', 'remark-slug', 'remark-autolink-headings', 'remark-external-links', 'remark-footnotes']` -- Version: **v2.0.0** +- Version: **>= v1.4.0** > You can take a look at the list of [remark plugins](https://github.com/remarkjs/remark/blob/master/doc/plugins.md#list-of-plugins). @@ -207,10 +207,22 @@ export default { - Type: `Array` - Default: `['rehype-minify-whitespace', 'rehype-sort-attribute-values', 'rehype-sort-attributes', 'rehype-raw']` -- Version: **v2.0.0** +- Version: **>= v1.4.0** > You can take a look at the list of [rehype plugins](https://github.com/rehypejs/rehype/blob/master/doc/plugins.md#list-of-plugins). +### `markdown.basePlugins` + + +Deprecated. Use `markdown.remarkPlugins` as a function instead. + + +### `markdown.plugins` + + +Deprecated. Use `markdown.remarkPlugins` as an array instead. + + ### `markdown.prism.theme` - Type: `String` diff --git a/docs/content/en/displaying.md b/docs/content/en/displaying.md index 2ddf60ea7..152727dd4 100644 --- a/docs/content/en/displaying.md +++ b/docs/content/en/displaying.md @@ -57,7 +57,7 @@ You can find an example in the [docs directory](https://github.com/nuxt/content/ ## Live Editing -> Available since v2.0 +> Available in version **>= v1.4.0** **In development**, you can edit your content by **double-clicking** on the `` component. A textarea will allow you to edit the content of the current file and will save it on the file-system. diff --git a/docs/content/en/fetching.md b/docs/content/en/fetching.md index 62f192d48..8d7840d4d 100644 --- a/docs/content/en/fetching.md +++ b/docs/content/en/fetching.md @@ -17,16 +17,16 @@ This module globally injects `$content` instance, meaning that you can access it - `options` - Type: `Object` - Default: `{}` - - Version: **v1.3.0** + - Version: **>= v1.3.0** - `options.deep` - Type: `Boolean` - Default: `false` - - Version: **v1.3.0** + - Version: **>= v1.3.0** - *Fetch files from subdirectories* - `options.text` - Type: `Boolean` - Default: `false` - - Version: **v2.0.0** + - Version: **>= v1.4.0** - *Returns the original markdown content in a `text` variable* - Returns a chain sequence diff --git a/docs/content/en/writing.md b/docs/content/en/writing.md index f31391ad2..5c60f4ebe 100644 --- a/docs/content/en/writing.md +++ b/docs/content/en/writing.md @@ -315,7 +315,7 @@ However, you cannot render #### Global components -Since **v2.0.0** and Nuxt **v2.13.0**, you can now put your components in `components/global/` directory so you don't have to import them in your pages. +Since **v1.4.0** and Nuxt **v2.13.0**, you can now put your components in `components/global/` directory so you don't have to import them in your pages. ```bash components/ diff --git a/docs/content/ja/changelog.md b/docs/content/ja/changelog.md deleted file mode 100644 index f935384b9..000000000 --- a/docs/content/ja/changelog.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: 変更ログ -description: 'nuxt/contentモジュールの異なるバージョンの変更点を学びます' -position: 8 -category: 入門 ---- - -## v2.0.0 - -### Markdown plugins - - - markdown.basePluginsとmarkdown.pluginsは削除されました。代わりにmarkdown.remarkPluginsとmarkdown.rehypePluginsを利用してください。 - - -- プラグインオプションのオーバーライドは接頭辞に`remark` / `rehype`を使用することで引き続き実行できます。たとえば、`externalLinks`は`remarkExternalLinks`になります。 -- `remarkPlugins` / `rehypePlugins`を利用することで、プラグインをオーバーライドしたり、新しいプラグインを追加することができるようになりました。 -- `~/plugins/remark-plugin.js`でローカルプラグインを利用できます。 -- `['remark-plugin', { option: 1 }]`のようにして、一行でプラグインの登録と設定が完了します。 - -完全なドキュメントは[ここ](/ja/configuration#markdown)にあります。 diff --git a/docs/content/ru/changelog.md b/docs/content/ru/changelog.md deleted file mode 100644 index 53596dfec..000000000 --- a/docs/content/ru/changelog.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: История изменений -description: 'Узнайте о изменениях между версиями модуля @nuxt/content.' -position: 8 -category: Начало ---- - -## v2.0.0 - -### Markdown плагины - - - markdown.basePlugins и markdown.plugins были заменены на markdown.remarkPlugins и markdown.rehypePlugins. - - -- В режиме разработки, вы можете использовать [редактирование в реальном времени](/displaying#live-editing) для вашего контента. -- Переопределение параметров плагинов все еще возможно, но с префиксом `remark` или `rehype`, к примеру `externalLinks` превращается в `remarkExternalLinks`. -- Теперь вы можете переопределить все плагины или добавить новый плагин, используя `remarkPlugins` / `rehypePlugins`. -- Вы можете использовать локальные плагины используя `~/plugins/remark-plugin.js`. -- Вы можете зарегистрировать и настроить плагин одной строкой, к примеру `['remark-plugin', { option: 1 }]`. - -Подробности описаны в [этом разделе](/configuration#markdown). diff --git a/lib/index.js b/lib/index.js index bf6f93ee9..edd0548ab 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,6 +2,7 @@ const { join, resolve } = require('path') const fs = require('fs').promises const mkdirp = require('mkdirp') const defu = require('defu') +const logger = require('consola').withScope('@nuxt/content') const middleware = require('./middleware') const Database = require('./database') @@ -14,6 +15,28 @@ module.exports = async function (moduleOptions) { const { content = {} } = Object.assign({}, this.options) Object.assign(content, moduleOptions) + if (content.markdown && content.markdown.basePlugins) { + logger.warn('Using `markdown.basePlugins` is deprecated. Use `markdown.remarkPlugins` as a function instead.') + const basePlugins = [...content.markdown.basePlugins] + content.markdown.remarkPlugins = () => basePlugins + delete content.markdown.basePlugins + } + if (content.markdown && content.markdown.plugins) { + logger.warn('Using `markdown.plugins` is deprecated. Use `markdown.remarkPlugins` as an array instead.') + const plugins = [...content.markdown.plugins] + if (content.markdown.remarkPlugins) { + if (typeof content.markdown.remarkPlugins === 'function') { + const oldPlugins = [...content.markdown.remarkPlugins()] + content.markdown.remarkPlugins = () => oldPlugins.concat(plugins) + } else { + content.markdown.remarkPlugins = content.markdown.remarkPlugins.concat(plugins) + } + } else { + content.markdown.remarkPlugins = plugins + } + delete content.markdown.plugins + } + const defaults = getDefaults({ dev: this.options.dev }) const mergedConfig = mergeConfig(content, defaults)