Skip to content

Commit

Permalink
feat: plugins compatibility (#183)
Browse files Browse the repository at this point in the history
* feat(lib): backwards compatibility with `plugins` and `basePlugins`

* docs: update for v1.4.0 instead of v2.0.0
  • Loading branch information
benjamincanac authored Jun 26, 2020
1 parent e7d9c7e commit ef648c0
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 73 deletions.
22 changes: 0 additions & 22 deletions docs/content/en/changelog.md

This file was deleted.

18 changes: 15 additions & 3 deletions docs/content/en/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -199,18 +199,30 @@ 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).
### `markdown.rehypePlugins`

- 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`

<base-alert>
Deprecated. Use `markdown.remarkPlugins` as a function instead.
</base-alert>

### `markdown.plugins`

<base-alert>
Deprecated. Use `markdown.remarkPlugins` as an array instead.
</base-alert>

### `markdown.prism.theme`

- Type: `String`
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/displaying.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<nuxt-content>` component. A textarea will allow you to edit the content of the current file and will save it on the file-system.

Expand Down
6 changes: 3 additions & 3 deletions docs/content/en/fetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/writing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
21 changes: 0 additions & 21 deletions docs/content/ja/changelog.md

This file was deleted.

22 changes: 0 additions & 22 deletions docs/content/ru/changelog.md

This file was deleted.

23 changes: 23 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down

0 comments on commit ef648c0

Please sign in to comment.