我想在 Sanity Studio 中上传 PDF,然后在主站点内容中链接到这些 PDF。
我在 Sanity Studio 中的 simpleBlockContent 输入中添加了对包含“文件”字段的文档的引用。
我为 PDF 创建了一个文档架构:
export default {
title: "PDF Upload",
name: "pdfDocument",
type: "document",
fields: [
{
name: "title",
type: "string",
title: "Title",
description: "This title will be used as a caption for the download.",
},
{
name: "pdfFile",
type: "file",
title: "PDF File",
options: {
accept: ".pdf",
},
validation: (Rule) => Rule.required(),
description: "Note that the file name will be visible to end users downloading the file.",
},
],
};
我试图在我的输入组件的架构中引用它:
export default {
title: "Simple Block Content",
name: "simpleBlockContent",
type: "array",
of: [
{
title: "Block",
type: "block",
styles: [],
marks: {
annotations: [
{
name: "pdfLink",
type: "object",
title: "PDF download link",
fields: [
{
name: "pdfReference",
type: "reference",
title: "PDF Document",
to: [{ type: "pdfDocument" }],
},
],
},
],
},
},
],
};
但是,当我在前端将 pdfLink 添加到我的 serializers.js 时,从处理所有其他页面内容的 _rawContent graphql 查询传递给它的数据中没有任何类似文件链接的内容。
如何访问构建链接到已上传资产的 URL 所需的信息?