-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsourcebit.js
More file actions
53 lines (51 loc) · 1.56 KB
/
sourcebit.js
File metadata and controls
53 lines (51 loc) · 1.56 KB
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
const _ = require('lodash');
const mapDeep = require('./src/utils/map-deep');
const isDev = process.env.NODE_ENV === 'development';
module.exports = {
plugins: [
{
module: require('sourcebit-source-sanity'),
options: {
accessToken: process.env.SANITY_TOKEN,
projectId: process.env.SANITY_PROJECT_ID,
dataset: process.env.SANITY_DATASET || 'production',
isPreview: isDev,
watch: isDev,
},
},
// Following plugin is defined by single transform function that
// transforms data to a format expected by react components
function ({ data }) {
return _.assign({}, data, {
objects: mapDeep(data.objects, (value) => {
const modelName = _.get(value, '__metadata.modelName');
// replace the asset object with the value of its "url" field
if (modelName === '__asset') {
return _.get(value, 'url');
}
// copy modelName to "_type" field
if (modelName) {
return _.assign({ _type: modelName }, value);
}
return value;
}),
});
},
{
module: require('sourcebit-target-next'),
options: {
liveUpdate: isDev,
pages: [
{ path: '/{slug}', predicate: _.matchesProperty('_type', 'landing') },
{ path: '/{slug}', predicate: _.matchesProperty('_type', 'page') },
],
commonProps: {
config: {
single: true,
predicate: _.matchesProperty('_type', 'site_config'),
},
},
},
},
],
};