makeSource
provides Contentlayer with the schema and configuration for your application.
#Usage
The code calling makeSource
should be placed in contentlayer.config.js
.
// contentlayer.config.js
import { makeSource } from 'contentlayer/source-files'
export default makeSource({
/* options */
})
#Options
#contentDirPath
(required)
Path to where the content lives, relative to the root of your project.
Example:
export default makeSource({
contentDirPath: 'content',
})
This would load content from a content
directory in your project.
#contentDirInclude
An array of paths that Contentlayer should include, 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.
This is useful when you have content spread across multiple directories in your project.
Default: []
Example:
This would target only content in the docs
directory, while using the default for contentDirExclude
(see below).
export default makeSource({
// ...
contentDirPath: '.',
contentDirInclude: ['docs'],
})
#contentDirExclude
An array of paths that Contentlayer should explicitly exclude, with the following conditions:
- Setting this option completely overrides the defaults.
- 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.
This is useful when you want to ignore a specific file or directory within your main content directory.
Default: ['node_modules', '.git', '.yarn', '.cache', '.next', '.contentlayer', 'package.json', 'tsconfig.json']
Example:
This ignores only the content/internal-docs
directory, but targets all other content files in the content
directory.
export default makeSource({
// ...
contentDirPath: './content',
contentDirExclude: ['internal-docs'],
})
#documentTypes
(required)
Your schema definitions for your project. See defineDocumentType
for usage.
#markdown
Specify remark and rehype plugins.
Options:
remarkPlugins
rehypePlugins
Example:
Here's an example that adds syntax highlighting.
import { makeSource } from 'contentlayer/source-files'
import highlight from 'rehype-highlight'
export default makeSource({
// ...
markdown: { rehypePlugins: [highlight] },
})
#mdx
Follows the same pattern as the markdown
option, but for MDX processing.
Options:
remarkPlugins
rehypePlugins
Example:
import { makeSource } from 'contentlayer/source-files'
import highlight from 'rehype-highlight'
export default makeSource({
// ...
mdx: { rehypePlugins: [highlight] },
})
#fieldOptions
Provides the ability to manipulate how fields are written when parsing the content source.
Options:
bodyFieldName
(default:body
): Name of the field containing the body/content extracted when the body type ismarkdown
ormdx
.typeFieldName
(default:type
): Name of the field containing the name of the document type (or nested document type).
Example:
export default makeSource({
fieldOptions: {
bodyFieldName: 'content',
typeFieldName: '__typename',
},
})
#date
Specify date options. Currently only supports:
timezone
: Specify the timezone when parsing dates. Based on @marsnusw/date-fns-tz.
Was this article helpful to you?
Provide feedback
Last edited on March 31, 2023.
Edit this page