-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.ts
105 lines (94 loc) · 2.68 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import type { CreateSchemaCustomizationArgs, CreateWebpackConfigArgs, GatsbyNode } from 'gatsby'
import path from 'path'
export const createPages: GatsbyNode['createPages'] = async ({ graphql, actions }) => {
const { createPage } = actions
const blogPostTemplate = path.resolve(`src/templates/Post.tsx`)
const result = await graphql<Queries.PagesQuery>(`
query Pages {
allMarkdownRemark(sort: { frontmatter: { date: DESC } }) {
edges {
node {
frontmatter {
slug
}
id
}
previous {
frontmatter {
slug
title
}
}
next {
frontmatter {
slug
title
}
}
}
}
}
`)
if (result.errors) {
throw result.errors
}
const posts = result.data?.allMarkdownRemark.edges
posts?.forEach(({ node, previous, next }) => {
createPage({
path: `/posts${node.frontmatter.slug}`,
component: blogPostTemplate,
context: {
id: node.id,
frontmatter__slug: node.frontmatter.slug,
previous: previous === null ? null : previous.frontmatter.slug,
previousTitle: previous === null ? null : previous.frontmatter.title,
next: next === null ? null : next.frontmatter.slug,
nextTitle: next === null ? null : next.frontmatter.title,
},
})
})
}
export const onCreateWebpackConfig: GatsbyNode['onCreateWebpackConfig'] = ({ actions }: CreateWebpackConfigArgs) => {
actions.setWebpackConfig({
resolve: {
alias: {
'@/components': path.resolve(__dirname, 'src/components'),
'@/images': path.resolve(__dirname, 'src/images'),
'@/styles': path.resolve(__dirname, 'src/styles'),
'@/utils': path.resolve(__dirname, 'src/utils'),
'@/contexts': path.resolve(__dirname, 'src/contexts'),
'@/layouts': path.resolve(__dirname, 'src/layouts'),
},
},
})
}
export const createSchemaCustomization: GatsbyNode['createSchemaCustomization'] = ({
actions,
}: CreateSchemaCustomizationArgs) => {
const { createTypes } = actions
createTypes(`
type SiteSiteMetadata {
title: String!
siteUrl: String!
description: String!
heroImage: String!
keywords: [String!]!
}
type Site implements Node {
siteMetadata: SiteSiteMetadata!
}
type Frontmatter {
title: String!
description: String!
slug: String!
date: Date! @dateformat
tags: [String!]!
heroImageAlt: String!
}
type MarkdownRemark implements Node {
frontmatter: Frontmatter!
id: String!
html: String!
}
`)
}