Included templates
contentlayer-config
contentlayer-config
Pasted files structure
├── contentlayer.config.ts
├── next.config.js
└── tsconfig.json
├── contentlayer.config.ts
├── next.config.js
└── tsconfig.json
Files contents
./contentlayer.config.ts
import { defineDocumentType, makeSource } from 'contentlayer/source-files'
import remarkGfm from 'remark-gfm'
import rehypeSlug from 'rehype-slug'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypePreetyCode from 'rehype-pretty-code'
export const Doc = defineDocumentType(() => ({
name: 'Doc',
filePathPattern: `**/*.mdx`,
fields: {
title: { type: 'string', required: true },
sortNum: { type: 'number', required: true },
},
computedFields: {
slug: { type: 'string', resolve: (doc) => `/${doc._raw.flattenedPath}` },
slugAsParams: { type: 'string', resolve: (doc) => doc._raw.flattenedPath.split('/').slice(1).join('/') },
},
contentType: 'mdx'
}))
export default makeSource({
contentDirPath: 'docs',
documentTypes: [Doc],
mdx: {
remarkPlugins: [remarkGfm],
rehypePlugins: [
rehypeSlug,
[
rehypePreetyCode,
{
theme: {
light: 'github-light',
dark: 'github-dark'
},
keepBackground: false,
onVisitLine: (node: any) => {
if (node.children.length === 0) {
node.children = [{ type: 'text', value: ' ' }]
}
},
onVisitHighlightedLine: (node: any) => {
node.properties.className.push('line--highlighted')
},
onVisitHighlitedWord: (node: any) => {
node.properties.className = ['word--highlighted']
}
}
],
[
rehypeAutolinkHeadings,
{
behavior: 'wrap',
properties: {
className: ['subheading--anchor'],
ariaLabel: 'Link to section'
}
}
]
]
}
})
./contentlayer.config.ts
import { defineDocumentType, makeSource } from 'contentlayer/source-files'
import remarkGfm from 'remark-gfm'
import rehypeSlug from 'rehype-slug'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypePreetyCode from 'rehype-pretty-code'
export const Doc = defineDocumentType(() => ({
name: 'Doc',
filePathPattern: `**/*.mdx`,
fields: {
title: { type: 'string', required: true },
sortNum: { type: 'number', required: true },
},
computedFields: {
slug: { type: 'string', resolve: (doc) => `/${doc._raw.flattenedPath}` },
slugAsParams: { type: 'string', resolve: (doc) => doc._raw.flattenedPath.split('/').slice(1).join('/') },
},
contentType: 'mdx'
}))
export default makeSource({
contentDirPath: 'docs',
documentTypes: [Doc],
mdx: {
remarkPlugins: [remarkGfm],
rehypePlugins: [
rehypeSlug,
[
rehypePreetyCode,
{
theme: {
light: 'github-light',
dark: 'github-dark'
},
keepBackground: false,
onVisitLine: (node: any) => {
if (node.children.length === 0) {
node.children = [{ type: 'text', value: ' ' }]
}
},
onVisitHighlightedLine: (node: any) => {
node.properties.className.push('line--highlighted')
},
onVisitHighlitedWord: (node: any) => {
node.properties.className = ['word--highlighted']
}
}
],
[
rehypeAutolinkHeadings,
{
behavior: 'wrap',
properties: {
className: ['subheading--anchor'],
ariaLabel: 'Link to section'
}
}
]
]
}
})
./next.config.js
/** @type {import('next').NextConfig} */
const { withContentlayer } = require('next-contentlayer')
const nextConfig = { reactStrictMode: true, swcMinify: true }
module.exports = withContentlayer(nextConfig)
./next.config.js
/** @type {import('next').NextConfig} */
const { withContentlayer } = require('next-contentlayer')
const nextConfig = { reactStrictMode: true, swcMinify: true }
module.exports = withContentlayer(nextConfig)
./tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": [
"./*"
],
"contentlayer/generated": [
"./.contentlayer/generated"
]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".contentlayer/generated"
],
"exclude": [
"node_modules"
]
}
./tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": [
"./*"
],
"contentlayer/generated": [
"./.contentlayer/generated"
]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".contentlayer/generated"
],
"exclude": [
"node_modules"
]
}