我在我的 Sanity/NextJS 项目中定义了一个简单的单例文档模式,用于模拟我的“Colophon”页面(richText
是自定义块字段类型):
export default {
title: 'Colophon',
name: 'colophon',
type: 'document',
__experimental_actions: ['update', 'publish'],
fields: [
{
title: 'Body',
name: 'body',
type: 'richText',
validation: Rule => Rule.required(),
},
],
};
我在 NextJS 应用程序中通过一个简单的查询来检索此文档:
export async function getStaticProps() {
const colophon = await client.fetch(`
*[_type == "colophon"][0]
`);
// ...
};
是否可以编写一个 GROQ 查询来检索模式中定义的元标题,即Colophon
?虽然这是一个单例文档,但如果可能的话,我想避免在我的项目中重复这个字符串。目前,我只能在结果中看到文档上的字段,即body
.
谢谢阅读!