This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
structureForAssetDocs.js
78 lines (73 loc) · 2.08 KB
/
structureForAssetDocs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
This is an example of how to use Structure Builder to organize image assets.
Usage:
import assetsStructure from './assetsStructure'
export default () => S.list()
.title('Content')
.items([
// other list items,
assetsStructure
])
*/
import React from 'react'
import S from '@sanity/desk-tool/structure-builder'
const AssetPreview = ({ document }) => {
const { displayed } = document
return (
displayed.url && (
<div style={{ padding: '1em' }}>
<img src={`${displayed.url}?w=600`} style={{ maxWidth: '100%' }} />
</div>
)
)
}
const AssetDoc = assetId =>
S.document()
.documentId(assetId)
.views([
S.view.component(AssetPreview).title('Image preview'),
S.view.form().title('Meta-information')
])
const assetsStructure = S.listItem()
.title('Assets')
.child(
S.list()
.title('Assets')
.items([
S.listItem()
.title('All images')
.child(S.documentTypeList('sanity.imageAsset').child(AssetDoc)),
// List images with width over 1000px
S.listItem()
.title('Large images (1000px+)')
.child(
S.documentList()
.title('Large images')
.filter(
'_type == "sanity.imageAsset" && metadata.dimensions.width > 1000'
)
.child(AssetDoc)
),
// List images with the file extension of “gif”
S.listItem()
.title('GIFs')
.child(
S.documentList()
.title('GIFs')
.filter('_type == "sanity.imageAsset" && extension == "gif"')
.child(AssetDoc)
),
// List images that has been uploaded with the unsplash asset selector
S.listItem()
.title('From Unsplash')
.child(
S.documentList()
.title('From Unsplash')
.filter(
'_type == "sanity.imageAsset" && source.name == "unsplash"'
)
.child(AssetDoc)
)
])
)
export default assetsStructure