diff --git a/docs/content/en/configuration.md b/docs/content/en/configuration.md index be414ca3d..10b9ed8fa 100644 --- a/docs/content/en/configuration.md +++ b/docs/content/en/configuration.md @@ -328,7 +328,7 @@ To add your custom parser write a function that gets as an argument the content **Example** -``` +```js{}[nuxt.config.js] const parseTxt = file => file.split('\n').map(line => line.trim()) // in Config: @@ -340,11 +340,33 @@ const parseTxt = file => file.split('\n').map(line => line.trim()) } ``` +### `editor` + +You can provide a custom editor for editing your markdown files in development. Set the `editor` option to a path to your editor component. The code of the default editor you can find [here](https://github.com/nuxt/content/blob/master/packages/content/templates/editor.vue). + + +```js{}[nuxt.config.js] +content: { + editor: '~/path/to/editor/component.vue' +} +``` + +Your component should implement the following: + +1. `v-model` for getting the markdown code. +2. prop `isEditing` is a boolean with the information if the editing is started and the component is shown. (this is optional) +3. when finished editing your component has to emit `endEdit` + + +You should be aware that you get the full markdown file content so this includes the front-matter. You can use `gray-matter` to split and join the markdown and the front-matter. + + ## Defaults ```js{}[nuxt.config.js] export default { content: { + editor: '~/.nuxt/content/editor.vue', apiPrefix: '_content', dir: 'content', fullTextSearchFields: ['title', 'description', 'slug', 'text'], diff --git a/packages/content/lib/index.js b/packages/content/lib/index.js index bf691784b..adbda8fa6 100644 --- a/packages/content/lib/index.js +++ b/packages/content/lib/index.js @@ -208,9 +208,15 @@ module.exports = async function (moduleOptions) { fileName: 'content/nuxt-content.dev.vue', src: join(__dirname, '../templates/nuxt-content.dev.vue'), options: { - apiPrefix: options.apiPrefixWithBase + apiPrefix: options.apiPrefixWithBase, + editor: options.editor } }) + // Add dev editor component + this.addTemplate({ + fileName: 'content/editor.vue', + src: join(__dirname, '..', 'templates', 'editor.vue') + }) } function isUrl (string) { diff --git a/packages/content/lib/utils.js b/packages/content/lib/utils.js index 0f71139b7..d0770aa9d 100644 --- a/packages/content/lib/utils.js +++ b/packages/content/lib/utils.js @@ -2,6 +2,7 @@ const logger = require('consola').withScope('@nuxt/content') const { camelCase } = require('change-case') const getDefaults = ({ dev = false } = {}) => ({ + editor: './editor.vue', watch: dev, liveEdit: true, apiPrefix: '_content', diff --git a/packages/content/templates/editor.vue b/packages/content/templates/editor.vue new file mode 100644 index 000000000..18c7f350d --- /dev/null +++ b/packages/content/templates/editor.vue @@ -0,0 +1,61 @@ +