Docs
Markdown文件
Markdown文件
博客和文档的工作原理。
内容发布者
Contentlayer 是一款基于 Markdown 的内容管理系统,具有灵活性和可扩展性。它可以让你使用 Markdown 文件组织内容,并提供一个直接的应用程序接口来访问应用程序中的数据。
您可以使用 Contentlayer 为博客文章、文档和页面等各种内容类型创建可重复使用的数据模型。
Markdown 文件中的 Frontmatter 允许你定义标题、描述、作者和图片等元数据,从而简化内容管理。
contentlayer.config.js
下面是一个 contentlayer.config.js 文件示例,用于在项目中配置 Contentlayer:
import { defineDocumentType, makeSource } from "contentlayer/source-files";
/** @type {import('contentlayer/source-files').ComputedFields} */
const computedFields = {
slug: {
type: "string",
resolve: (doc) => `/${doc._raw.flattenedPath}`,
},
slugAsParams: {
type: "string",
resolve: (doc) => doc._raw.flattenedPath.split("/").slice(1).join("/"),
},
};
export const Doc = defineDocumentType(() => ({
name: "Doc",
filePathPattern: `docs/**/*.mdx`,
contentType: "mdx",
fields: {
title: {
type: "string",
required: true,
},
description: {
type: "string",
},
published: {
type: "boolean",
default: true,
},
},
computedFields,
}));
export const Post = defineDocumentType(() => ({
name: "Post",
filePathPattern: `blog/**/*.mdx`,
contentType: "mdx",
fields: {
title: {
type: "string",
required: true,
},
description: {
type: "string",
},
date: {
type: "date",
required: true,
},
published: {
type: "boolean",
default: true,
},
image: {
type: "string",
required: true,
},
authors: {
type: "list",
of: { type: "string" },
required: true,
},
},
computedFields,
}));
export const Page = defineDocumentType(() => ({
name: "Page",
filePathPattern: `pages/**/*.mdx`,
contentType: "mdx",
fields: {
title: {
type: "string",
required: true,
},
description: {
type: "string",
},
},
computedFields,
}));
export default makeSource({
contentDirPath: "./content",
documentTypes: [Page, Doc, Post],
mdx: {},
});该文件配置 Contentlayer 在指定目录(content/blog, content/authors, content/docs, content/pages)中查找 Markdown 文件。它还定义了项目中使用的不同文档类型,以及与每种文档类型相关的字段。
您可以根据项目需要自定义该文件,添加新的文件类型或根据具体要求调整现有字段。
头条新闻
以下是每个部件的所有正面图案列表:
作者
---
title: mickasmt
avatar: /_static/avatars/mickasmt.jpg
twitter: mickasmt
---博客
---
title: Deploying Next.js Apps
description: How to deploy your Next.js apps on Vercel.
image: /_static/blog/blog-post-3.jpg
date: "2023-01-02"
authors:
- mickasmt
---文档
---
title: Database
description: How to config your Neon database.
---页面
---
title: Privacy
description: The Privacy Policy for your app.
---