Skip to content

Releases: contentlayerdev/contentlayer

0.2.4

19 Apr 13:19
17c739d
Compare
Choose a tag to compare

Changes

  • Fix JSON import assertions for Node 17 (and higher). See #153 for more.
  • Improved error printing

0.2.3

15 Apr 09:47
d0424fa
Compare
Choose a tag to compare

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

0.2.2

13 Apr 08:39
c4c4703
Compare
Choose a tag to compare

Changes

  • Fix react/jsx-runtime import error due to breaking change from React 17 to React 18. (Hopefully fixes #162 for good 🤞)

P.S. We're gearing up to officially launch Contentlayer in beta soon. Stay tuned for a fancy new website with much improved documentation and interactive examples. 🚀

0.2.1

31 Mar 17:19
a2b3c25
Compare
Choose a tag to compare

🚨 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

0.1.2

28 Feb 15:52
34c6bdd
Compare
Choose a tag to compare

Changes

  • next-contentlayer: Set onDemandEntries.maxInactiveAge Next.js config to one hour by default in order to improve live-reloading behaviour for content changes. (closes #63)

0.1.1

13 Feb 17:21
Compare
Choose a tag to compare

Changes

  • Fix exports and typesVersions entries in generated .contentlayer/package.json file

0.1.0

11 Feb 13:55
a927be7
Compare
Choose a tag to compare

🚨 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:

  1. Delete node_modules/.contentlayer folder and .contentlayer symlink.

  2. Add the new directory to your tsconfig.json / jsconfig.json as shown below:

    {
      "compilerOptions": {
        "baseUrl": ".",
        "paths": {
          "contentlayer/generated": ["./.contentlayer/generated"]
    //    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        }
      },
      "include": ["next-env.d.ts", "**/*.tsx", "**/*.ts", ".contentlayer/generated"]
    //                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    }
  3. Rename import statements from .contentlayer/data and .contentlayer/types to contentlayer/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 bodyType in your document definitions, then you don't need to do anything.

  • If you were using markdown or mdx as the bodyType for a document type definition, change bodyType to contentType.

    // old
    defineDocumentType(() => ({
      name: "Page",
      filePathPattern: `**/*.mdx`,
      bodyType: "mdx"
    })
    
    // new
    defineDocumentType(() => ({
      name: "Page",
      filePathPattern: `**/*.mdx`,
      contentType: "mdx"
    })
  • If you were using bodyType and had it set to none, 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

14 Jan 11:11
47da88b
Compare
Choose a tag to compare

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: true in type: 'reference' field definitions (tracked via #86)

0.0.33

01 Dec 17:51
44d7c73
Compare
Choose a tag to compare

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

0.0.32

15 Nov 10:35
b8ef694
Compare
Choose a tag to compare

Changes

  • Fix problem with incorrectly linked .contentlayer folder leading to build errors (e.g. on Vercel). (closes #44)