-
Notifications
You must be signed in to change notification settings - Fork 4
/
constants.js
147 lines (136 loc) · 2.72 KB
/
constants.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
export const IGNORE_FLAG = 'svelte-preprocess-import-assets-ignore'
export const DEFAULT_ASSET_PREFIX = '___ASSET___'
export const ALLOWED_REL = [
'stylesheet',
'icon',
'shortcut icon',
'mask-icon',
'apple-touch-icon',
'apple-touch-icon-precomposed',
'apple-touch-startup-image',
'manifest',
'prefetch',
'preload',
]
export const ALLOWED_ITEMPROP = [
'image',
'logo',
'screenshot',
'thumbnailurl',
'contenturl',
'downloadurl',
'duringmedia',
'embedurl',
'installurl',
'layoutimage',
]
export const ALLOWED_META_NAME = [
'msapplication-tileimage',
'msapplication-square70x70logo',
'msapplication-square150x150logo',
'msapplication-wide310x150logo',
'msapplication-square310x310logo',
'msapplication-config',
'twitter:image',
]
export const ALLOWED_META_PROPERTY = [
'og:image',
'og:image:url',
'og:image:secure_url',
'og:audio',
'og:audio:secure_url',
'og:video',
'og:video:secure_url',
'vk:image',
]
/** @type {import('.').AssetSource[]} */
export const DEFAULT_SOURCES = [
{
tag: 'audio',
srcAttributes: ['src'],
},
{
tag: 'embed',
srcAttributes: ['src'],
},
{
tag: 'img',
srcAttributes: ['src'],
srcsetAttributes: ['srcset'],
},
{
tag: 'input',
srcAttributes: ['src'],
},
{
tag: 'object',
srcAttributes: ['src'],
},
{
tag: 'source',
srcAttributes: ['src'],
srcsetAttributes: ['srcset'],
},
{
tag: 'track',
srcAttributes: ['src'],
},
{
tag: 'video',
srcAttributes: ['poster', 'src'],
},
{
tag: 'image',
srcAttributes: ['href', 'xlink:href'],
},
{
tag: 'use',
srcAttributes: ['href', 'xlink:href'],
},
{
tag: 'link',
srcAttributes: ['href'],
srcsetAttributes: ['imagesrcset'],
filter({ attribute, attributes }) {
if (
attributes.rel &&
ALLOWED_REL.includes(attributes.rel.trim().toLowerCase())
) {
return true
}
if (
attribute !== 'imagesrcset' &&
attributes.itemprop &&
ALLOWED_ITEMPROP.includes(attributes.itemprop.trim().toLowerCase())
) {
return true
}
return false
},
},
{
tag: 'meta',
srcAttributes: ['content'],
filter({ attributes }) {
if (
attributes.name &&
ALLOWED_META_NAME.includes(attributes.name.trim().toLowerCase())
) {
return true
}
if (
attributes.property &&
ALLOWED_META_PROPERTY.includes(attributes.property.trim().toLowerCase())
) {
return true
}
if (
attributes.itemprop &&
ALLOWED_ITEMPROP.includes(attributes.itemprop.trim().toLowerCase())
) {
return true
}
return false
},
},
]