Releases: contentlayerdev/contentlayer
0.2.4
0.2.3
Changes
- Improved error handling for invalid date values
- Upgraded dependencies
- Use
mdx-bundler@9- Now used MDX 2 instead of XDM (via #175 thanks @browniefed) - Updated other internal dependencies
- Use
0.2.2
0.2.1
🚨 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
⬆️ 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
contentDirPathor absolute. - An empty array means that all files in
contentDirPathwill 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.tsThe 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: truein your Contentlayer config.
-
Show warnings when
pathorbaseUrlare missing fromtsconfig.jsonorjsconfig.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
0.1.2
Changes
next-contentlayer: SetonDemandEntries.maxInactiveAgeNext.js config to one hour by default in order to improve live-reloading behaviour for content changes. (closes #63)
0.1.1
Changes
- Fix
exportsandtypesVersionsentries in generated.contentlayer/package.jsonfile
0.1.0
🚨 This release contains two (2) breaking changes. See Upgrading below for more information and instructions on brings your project up to date.
Changes
💥 [Breaking] Generated files are now placed in a .contentlayer/generated directory at the root of the project. See Updating below for details. #65 #113
💥 [Breaking] bodyType will be replaced by contentType. See Upgrading below for details.
✨ The full markdown (or MDX) file content (including the frontmatter) will be passed to remark/rehype plugins during process only for the main body of the file. #106
✨ Live-reloading in Next.js via the useLiveReload has been improved. Reloading no longer scrolls to the top of the page and fixes a bug mentioned in #109.
✨ Types are generated as part of the npm postinstall script. This ensures types will exist right after cloning the project. #114 (also provides a workaround for #118)
✨ Improve type generation. #69 #89
✨ Upgrade to MDX v2 (via mdx-bundler@8).
Upgrading
The following sections outline breaking changes introduced in this version. Follow the steps below to upgrade your project.
1. New Directory for Generated Files
The .contentlayer directory was previously symlinked to a directory within node modules that caused a number of problems. By generating directly to a .contentlayer/generated directory, we see the following benefits:
- Live reload of schema changes now work without having to restart TypeScript server in VS Code. #65
- Auto-import works.
- Symlinks are no longer needed.
- Easier process to learn for new users.
Upgrade steps:
-
Delete
node_modules/.contentlayerfolder and.contentlayersymlink. -
Add the new directory to your
tsconfig.json/jsconfig.jsonas shown below:{ "compilerOptions": { "baseUrl": ".", "paths": { "contentlayer/generated": ["./.contentlayer/generated"] // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } }, "include": ["next-env.d.ts", "**/*.tsx", "**/*.ts", ".contentlayer/generated"] // ^^^^^^^^^^^^^^^^^^^^^^^^^^^ } -
Rename import statements from
.contentlayer/dataand.contentlayer/typestocontentlayer/generated
// old
import { allPosts } from ".contentlayer/data"
import { Post } from ".contentlayer/types"
// new
import { allPosts, Post } from "contentlayer/generated"2. Processing Main Content of a markdown/MDX File
bodyType has been deprecated in favor of contentType. The new options for contentType are markdown or mdx. This determines how the main body content will be processed.
This fixes an issue in which a .md was (intentionally) using MDX code in its main body area. This is now possible by specifying mdx as the contentType in the document type definition.
Upgrade steps:
-
If you weren't using
bodyTypein your document definitions, then you don't need to do anything. -
If you were using
markdownormdxas thebodyTypefor a document type definition, changebodyTypetocontentType.// old defineDocumentType(() => ({ name: "Page", filePathPattern: `**/*.mdx`, bodyType: "mdx" }) // new defineDocumentType(() => ({ name: "Page", filePathPattern: `**/*.mdx`, contentType: "mdx" })
-
If you were using
bodyTypeand had it set tonone, remove it. The body will be assumed to be an empty string if there is no content, but the property will always exist in the output document.// old defineDocumentType(() => ({ name: "Page", filePathPattern: `**/*.md`, bodyType: "none" }) // new defineDocumentType(() => ({ name: "Page", filePathPattern: `**/*.md` })
0.0.34
Changes
- Fixed: Optional list should not require the field to be set in the frontmatter. (closes #95)
- Fixed ESM export mapping for
next-contentlayer/hooks. (closes #48) - Experimental support for embedding referenced documents by setting
embedDocument: trueintype: 'reference'field definitions (tracked via #86)
0.0.33
Changes
- Improved error handling for singleton document types (i.e. Contentlayer now shows a helpful error message if no document was found)
- Improved data validation for MD(X) frontmatter
- Updated underlying dependencies
