sanity - 通过 Sanity Studio 中的引用链接时,如何访问资产的 URL?
问题描述
我想在 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 所需的信息?
解决方案
根据文档,我还没有在序列化程序中执行此操作,但看起来资产 URL 应该可以在返回的文档中访问:
退回资产文件示例:
{
"_id": "image-abc123_0G0Pkg3JLakKCLrF1podAdE9-538x538-jpg",
"_type": "sanity.imageAsset", // type is prefixed by sanity schema
"assetId": "0G0Pkg3JLakKCLrF1podAdE9",
"path": "images/myproject/mydataset/abc123_0G0Pkg3JLakKCLrF1podAdE9-538x538.jpg",
"url": "https://cdn.sanity.io/images/myproject/mydataset/abc123_0G0Pkg3JLakKCLrF1podAdE9-538x538.jpg",
"originalFilename": "bicycle.jpg",
"size": 2097152, // File size, in bytes
"metadata": {
"dimensions": {
"height": 538,
"width": 538,
"aspectRatio": 1.0
},
"location":{ // only present if the original image contained location metadata
"lat": 59.9241370,
"lon": 10.7583846,
"alt": 21.0
}
}
}
推荐阅读
- firebase - 火力基地 | 重新加载后在当前目录中找不到 index.html
- r - 在 tidymodel 自动绘图中出现错误: pset$object[[which(pset$id == x_col)]] 中的错误:尝试在 get1index 中选择少于一个元素
- flutter - 如何从覆盖另一个的小部件中删除透明度?
- php - Woocommerce 多类别产品的动态面包屑
- sql - 您如何连接多个表并查找行项目的计数?
- c++ - 如何在 C++ 中重新定位一个数组中的元素
- pandas - 处理包含多个排列和组合的熊猫中超过 600 列的 excel 文件的最佳方法是什么?
- php - 基于碳日期的准确日期格式
- php - Docker php:X-fpm-stretch with apache
- android - Android Material 文本输入布局结束图标不显示