-
Notifications
You must be signed in to change notification settings - Fork 1
/
stackbit.config.ts
58 lines (55 loc) · 2.08 KB
/
stackbit.config.ts
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
import { defineStackbitConfig, DocumentStringLikeFieldNonLocalized, SiteMapEntry } from '@stackbit/types';
import { GitContentSource } from '@stackbit/cms-git';
import { allModels } from 'sources/local/models';
const gitContentSource = new GitContentSource({
rootPath: __dirname,
contentDirs: ['content'],
models: Object.values(allModels),
assetsConfig: {
referenceType: 'static',
staticDir: 'public',
uploadDir: 'images',
publicPath: '/'
}
});
export const config = defineStackbitConfig({
stackbitVersion: '~0.6.0',
ssgName: 'nextjs',
nodeVersion: '18',
styleObjectModelName: 'ThemeStyle',
contentSources: [gitContentSource],
presetSource: {
type: 'files',
presetDirs: ['sources/local/presets']
},
siteMap: ({ documents, models }): SiteMapEntry[] => {
const pageModels = models.filter((model) => model.type === 'page').map((model) => model.name);
return documents
.filter((document) => pageModels.includes(document.modelName))
.map((document) => {
let slug = (document.fields.slug as DocumentStringLikeFieldNonLocalized)?.value;
if (!slug) return null;
/* Remove the leading slash in order to generate correct urlPath
regardless of whether the slug is '/', 'slug' or '/slug' */
slug = slug.replace(/^\/+/, '');
switch (document.modelName) {
case 'PostFeedLayout':
return {
urlPath: '/blog',
document: document
};
case 'PostLayout':
return {
urlPath: `/blog/${slug}`,
document: document
};
default:
return {
urlPath: `/${slug}`,
document: document
};
}
});
}
});
export default config;