Skip to content

Commit

Permalink
next-contentlayer: BREAKING Change withContentlayer API and introduce…
Browse files Browse the repository at this point in the history
… createContentlayerPlugin #140
  • Loading branch information
schickling committed Mar 28, 2022
1 parent 820f12f commit 4156e94
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
39 changes: 37 additions & 2 deletions packages/next-contentlayer/src/index-cjs.ts
Expand Up @@ -2,11 +2,29 @@ import type { NextConfig } from 'next'

export type { NextConfig }

type PluginOptions = {}
export type PluginOptions = {}

let devServerStarted = false

module.exports.withContentlayer =
const defaultPluginOptions: PluginOptions = {}
module.exports.defaultPluginOptions = defaultPluginOptions

/**
* This function allows you to provide custom plugin options (currently there are none however).
*
* @example
* ```js
* // next.config.mjs
* import { createContentlayerPlugin } from 'next-contentlayer'
*
* const withContentlayer = createContentlayerPlugin()
*
* export default withContentlayer({
* // My Next.js config
* })
* ```
*/
module.exports.createContentlayerPlugin =
(_pluginOptions: PluginOptions = {}) =>
(nextConfig: Partial<NextConfig> = {}): Partial<NextConfig> => {
// could be either `next dev` or just `next`
Expand Down Expand Up @@ -59,3 +77,20 @@ module.exports.withContentlayer =
},
}
}

/**
* Next.js plugin for Contentlayer with default options.
*
* If you want to provide custom plugin options, please use {@link createContentlayerPlugin} instead.
*
* @example
* ```js
* // next.config.mjs
* import { withContentlayer } from 'next-contentlayer'
*
* export default withContentlayer({
* // My Next.js config
* })
* ```
*/
module.exports.withContentlayer = module.exports.createContentlayerPlugin(defaultPluginOptions)
36 changes: 35 additions & 1 deletion packages/next-contentlayer/src/index.ts
Expand Up @@ -8,7 +8,24 @@ export type PluginOptions = {}

let devServerStarted = false

export const withContentlayer =
export const defaultPluginOptions: PluginOptions = {}

/**
* This function allows you to provide custom plugin options (currently there are none however).
*
* @example
* ```js
* // next.config.mjs
* import { createContentlayerPlugin } from 'next-contentlayer'
*
* const withContentlayer = createContentlayerPlugin()
*
* export default withContentlayer({
* // My Next.js config
* })
* ```
*/
export const createContentlayerPlugin =
(_pluginOptions: PluginOptions = {}) =>
(nextConfig: Partial<NextConfig> = {}): Partial<NextConfig> => {
// could be either `next dev` or just `next`
Expand Down Expand Up @@ -59,3 +76,20 @@ export const withContentlayer =
},
}
}

/**
* Next.js plugin for Contentlayer with default options.
*
* If you want to provide custom plugin options, please use {@link createContentlayerPlugin} instead.
*
* @example
* ```js
* // next.config.mjs
* import { withContentlayer } from 'next-contentlayer'
*
* export default withContentlayer({
* // My Next.js config
* })
* ```
*/
export const withContentlayer = createContentlayerPlugin(defaultPluginOptions)

0 comments on commit 4156e94

Please sign in to comment.