在博客项目中使用 Noutious

注意事项

Noutious 只能运行在 Node 侧,请不要直接在客户端组件中调用它。

初始化后的 noutious 导出了 blogdocs 两个项。若想在博客项目中使用 Noutious 作为内容管理系统,你应当使用 noutious.blog

你需要将博客内容放入 Noutious 工作目录下的 blog/ 目录。

查询全部文章

const posts = await noutious.blog.queryPosts({
	// 查询参数
	sort: { date: -1 }, // 根据日期排序文章,可接受值:1 | -1
	include: { categories: 'Noutious' }, // 根据特定的 Front Matter 项和值筛选文章
	limit: 5, // 限制文章查询数量
});

查询参数类型 | 返回内容类型

查询全部分类

const categories = await noutious.blog.queryCategories();

返回参数类型:string | string[]

查询全部标签

const tags = await noutious.blog.queryTags()

返回参数类型:string | string[]

查询特定文章

const post = await noutious.blog.queryPost(
	// 通过 slug 查询文章
	'hello-world',
	// 根据日期排序文章,用于前 / 后一篇文章查询。
	{ sort: { date: -1 } }
)

返回内容类型