-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsourcebit.js
63 lines (58 loc) · 2.32 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
const path = require('path');
const isDev = process.env.NODE_ENV === 'development';
module.exports = {
plugins: [
/**
* The `sourcebit-source-filesystem` plugin reads content files from the provided `options.sources`,
* and generates array of objects that are passed to subsequent plugins.
*/
{
module: require('sourcebit-source-filesystem'),
options: {
watch: isDev,
sources: [
{ name: 'pages', path: path.join(__dirname, 'content/pages') },
{ name: 'data', path: path.join(__dirname, 'content/data') }
]
}
},
/**
* converts { __metadata, frontmatter, markdown }
* to { __metadata, ...frontmater, markdown_content: markdown }
*/
({ data }) => {
const objects = data.objects.map((object) => {
if ('frontmatter' in object) {
return {
__metadata: object.__metadata,
...object.frontmatter,
markdown_content: object.markdown ?? null
};
}
return object;
});
return {
...data,
objects
};
},
/**
* The `sourcebit-target-next` plugin receives objects generated by `sourcebit-source-filesystem` plugin,
* and generates new data that is consumed by Next.js `getStaticPaths` and `getStaticProps` methods.
* The generated data is cached and stored inside `.sourcebit-nextjs-cache.json` file.
*
* The generated data is an object with three properties:
* - objects: Array of objects representing all content files loaded by the `sourcebit-source-filesystem` plugin.
* - pages: Array of objects representing site pages props. This array is generated by the `pages()` method.
* - props: Object with common props that will be merged with props of every page. This object is generated by
* the `commonProps()` method.
*/
{
module: require('sourcebit-target-next'),
options: {
liveUpdate: isDev,
flattenAssetUrls: true
}
}
]
};