-
Notifications
You must be signed in to change notification settings - Fork 0
/
sourcebit.js
67 lines (61 loc) · 1.63 KB
/
sourcebit.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
const path = require('path');
const { matchesProperty } = require('lodash');
// const { sourcebitDataClient } = require('sourcebit-target-next');
const isDev = process.env.NODE_ENV === 'development';
const sourcebitSourceFileSystem = {
module: require('sourcebit-source-filesystem'),
options: {
watch: isDev,
sources: [
{ name: 'data', path: path.join(__dirname, 'content/data') },
{ name: 'pages', path: path.join(__dirname, 'content/pages') }
]
}
};
/**
* converts { __metadata, frontmatter, markdown }
* to { __metadata, ...frontmater, content: markdown }
*/
function flattenMarkdownData() {
return ({ data }) => {
const objects = data.objects.map((model) => {
if ('frontmatter' in model) {
return {
__metadata: model.__metadata,
...model.frontmatter,
content: model.markdown || null
};
}
return model;
});
return {
...data,
objects
};
};
}
const sourcebitTargetNext = {
module: require('sourcebit-target-next'),
options: {
liveUpdate: isDev,
flattenAssetUrls: true,
// Define common props that will be provided to all pages
commonProps: {
site: {
single: true,
predicate: matchesProperty('__metadata.id', 'content/data/config.json')
}
},
// Define which source objects represent pages
// and under which paths they should be available.
pages: [
{
path: '/{slug}',
predicate: matchesProperty('__metadata.modelName', 'Page')
}
]
}
};
module.exports = {
plugins: [sourcebitSourceFileSystem, flattenMarkdownData(), sourcebitTargetNext]
};