This repository was archived by the owner on Jun 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstackbit.config.ts
59 lines (54 loc) · 1.95 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
59
import { defineStackbitConfig, SiteMapEntry, SiteMapOptions, DocumentWithSource, DocumentStringLikeFieldNonLocalized } from '@stackbit/types';
import { ExampleContentSource } from './example-content-source/example-content-source';
import { normalizeSlug } from './utils/common';
export default defineStackbitConfig({
stackbitVersion: '0.6.0',
ssgName: 'nextjs',
nodeVersion: '16',
contentSources: [
new ExampleContentSource({
projectId: 'example',
databaseFilePath: process.env.EXAMPLE_DATABASE_FILE
})
],
modelExtensions: [
{
type: 'page',
name: 'post'
}
],
siteMap: (options: SiteMapOptions) => {
const postPages = options.documents
.filter((document) => {
return document.modelName === 'post';
})
.map((document): SiteMapEntry | null => {
const slug = getStringField(document, 'slug');
if (!slug) return null;
const title = getStringField(document, 'title');
return {
stableId: document.id,
label: title,
urlPath: `/posts${normalizeSlug(slug)}`,
document: {
srcType: document.srcType,
srcProjectId: document.srcProjectId,
modelName: document.modelName,
id: document.id
}
};
})
.filter(Boolean) as SiteMapEntry[];
const homepage: SiteMapEntry = {
urlPath: '/',
stableId: 'home',
label: 'Home',
isHomePage: true
};
const pages = [homepage, ...postPages];
return pages;
}
});
function getStringField(document: DocumentWithSource, field: string) {
return (document.fields[field] as DocumentStringLikeFieldNonLocalized)?.value;
}