-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.ts
58 lines (51 loc) · 1.15 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
46
47
48
49
50
51
52
53
54
55
56
57
58
// Because we used ts-node in gatsby-config.js, this file will automatically be
// imported by Gatsby instead of gatsby-node.js.
// Use the type definitions that are included with Gatsby.
import { GatsbyNode } from "gatsby";
import { resolve } from "path";
import { Post, PostQuery } from "./src/models/post";
import { getAllPosts } from "./src/functions/post";
export const createPages: GatsbyNode["createPages"] = async ({
actions,
graphql,
}) => {
const { createPage } = actions;
const query: {
errors?: any;
data?: PostQuery;
} = await graphql(`
query {
allHashNodePost {
nodes {
id
slug
title
dateAdded
content: contentMarkdown
}
}
allMediumFeed {
nodes {
id
slug
title
dateAdded: date
content
link
}
}
}
`);
const posts = query.data == null ? [] : getAllPosts(query.data!);
posts.forEach(node => {
const id = node.id;
if (!id) return;
createPage({
path: id,
component: resolve(__dirname, "./src/components/post.tsx"),
context: {
...node
},
});
});
};