-
Notifications
You must be signed in to change notification settings - Fork 18
/
gridsome.server.js
34 lines (30 loc) · 1.17 KB
/
gridsome.server.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
const path = require('path')
const gridsomeConfig = require('./gridsome.config')
function resolveAlias(filepath) {
if (filepath.startsWith('@assets/')) {
return filepath.replace('@assets', path.join(__dirname, 'src', 'assets'))
}
return filepath
}
module.exports = function (api) {
api.loadSource(({ addCollection, addMetadata }) => {
// Use the Data Store API here: https://gridsome.org/docs/data-store-api/
addMetadata('settings', gridsomeConfig.settings);
});
api.createPages(({ createPage }) => {
// Use the Pages API here: https://gridsome.org/docs/pages-api/
});
api.onCreateNode(options => {
if (options.internal.typeName !== 'MarkdownPage') {
return null;
}
// Set content type and timestamp for markdown pages
options.contentType = options.fileInfo.directory.split('/')[0];
options.createdAt = options.created ? new Date(options.created).getTime() : false;
// Set optional header/teaser images
options.header = options.header ? resolveAlias(options.header) : null;
options.teaser = options.teaser ? resolveAlias(options.teaser) : null;
options.hidden = options.hidden ?? false;
return options;
});
};