Skip to content

0.2.1

Compare
Choose a tag to compare
@schickling schickling released this 31 Mar 17:19
· 305 commits to main since this release
a2b3c25

🚨 This release contains one (1) breaking change. See below for more information and instructions to bring your project up to date.

💥 Breaking Changes

Because most folks are using Contentlayer as a Next.js plugin and not "calling" before using it, the API for wrapping the Next.js config object export has changed. #140

⚠️ Note: This only affects the Next.js plugin.

⬆️ To upgrade, remove the () following withContentlayer in your Next configuration file:

// next.config.mjs

import { withContentlayer } from 'next-contentlayer'

// ✅  Do This                 ▼▼▼ no additional `()` needed
export default withContentlayer({
  // Your Next.js config...
})

// ❌  Not This                 ▼▼
export default withContentlayer()({
  // Your Next.js config...
})

✨ This also introduces a createContentlayerPlugin API which allows for providing some non-default Contentlayer configuration options:

import { createContentlayerPlugin } from 'next-contentlayer'

const withContentlayer = createContentlayerPlugin({
  // Additional Contentlayer config options
})

export default withContentlayer({
  // Your Next.js config...
})

Other Changes

✨ Include/Exclude Content Files

Previously, Contentlayer picked up all files matching the filePathPattern within the contentDirPath. You can now explicitly exclude or include paths within the contentDirPath. This is especially useful when using your project root (.) to target content. #122

Both are an array of strings, with the following conditions:

  • They can be either files or directories.
  • The paths need to be relative to contentDirPath or absolute.
  • An empty array means that all files in contentDirPath will be included.
  • Glob/wildcard patterns (e.g. using *) are not supported yet.

There are sensible defaults in place. See below for details.

contentDirInclude should be an array of paths that Contentlayer should include. Defaults to []. This is useful when you have content spread across multiple directories in your project. Here is an example that targets only the docs directory in your project:

export default makeSource({
  // ...
  contentDirPath: ".",
  contentDirInclude: ["docs"],
});

contentDirExclude is an array of paths Contentlayer should explicitly exclude. When you set this, it overrides the default, which is: ['node_modules', '.git', '.yarn', '.cache', '.next', '.contentlayer', 'package.json', 'tsconfig.json'].

This is useful when you want to ignore a specific file or directory within your main content directory.

export default makeSource({
  // ...
  contentDirPath: "./content",
  contentDirExclude: ["internal-docs"],
});

✨ Improved Generated Content Structure for better performance

The .contentlayer/generated structure has changed slightly. Previously, it looked like this:

.contentlayer/generated/
├── Page/
│   ├── index.md.json
│   ├── about.md.json
│   └── blog.md.json
├── allPages.mjs
├── index.d.ts
├── index.mjs
└── types.d.ts

The all*.mjs files have been adding in the type directory as both _index.mjs and _index.json. The .mjs is used when running next dev for live reloading capabilities, while the JSON file is used to speed up production builds.

The new structure looks like this:

.contentlayer/generated/
├── Page/
│   ├── _index.mjs <-- for dev
│   ├── _index.json <-- for build
│   ├── index.md.json
│   ├── about.md.json
│   └── blog.md.json
├── index.d.ts
├── index.mjs
└── types.d.ts

🏎 This has improved build performance significantly!

✨ ESM-compatible JSON File Imports

assert { type: 'json' } is required when importing JSON files using Node v16.14 or higher. However, it is invalid syntax when using an earlier version of Node.

These assertions are now automatically added to generated .mjs files based on the current version of Node. #153

✨ Improved Developer Experience

Several updates provide better feedback when running Contentlayer.

  • You can now disable alias warnings by defining disableImportAliasWarning: true in your Contentlayer config.

    image
  • Show warnings when path or baseUrl are missing from tsconfig.json or jsconfig.json. #132

  • Fix an issue with the output suggesting it's skipping when it was actually processing appropriately. #156

Additional Updates

✨ Add support for React 18. #162
✨ Updated dependencies
✨ Content will update when changing Contentlayer configuration. #99