-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.ts
45 lines (40 loc) · 1.18 KB
/
gatsby-node.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
import { resolve } from 'path';
import { slugify } from './src/utils/slug';
import { CreatePagesArgs } from 'gatsby';
type NotionPagesQuery = {
allNotion: {
nodes: [{
id: string,
title: string,
markdownString: string
}]
}
}
const notionQuery = `query {
allNotion {
nodes {
id
title
markdownString
}
}
}`;
// Create blog pages dynamically
export async function createPages(params: CreatePagesArgs): Promise<void> {
const { createPage } = params.actions;
const blogPostTemplate = resolve('src/components/blog/blog-post.component.tsx');
const result = await params.graphql<NotionPagesQuery>(notionQuery);
result.data?.allNotion.nodes.forEach(node => {
const postUrl = slugify(node.title);
params.reporter.info(`Creating Notion blog post page with URL ${postUrl}...`);
createPage({
path: postUrl,
component: blogPostTemplate,
context: {
title: node.title,
content: node.markdownString
},
});
params.reporter.info(`Notion blog post page with URL ${postUrl} created.`);
});
}