-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
executable file
·103 lines (93 loc) · 2.46 KB
/
gatsby-node.js
File metadata and controls
executable file
·103 lines (93 loc) · 2.46 KB
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
const path = require('path')
exports.onCreateWebpackConfig = ({ getConfig, actions, plugins }) => {
const prodMode = getConfig().mode === 'production';
actions.setWebpackConfig({
devtool: prodMode ? false : 'eval-cheap-source-map',
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
alias: {
"@": path.join(__dirname, "src"),
}
},
plugins: [
plugins.define({
'__REACT_DEVTOOLS_GLOBAL_HOOK__': `({ isDisabled: true })`
})
],
})
}
exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage } = actions
const blogPostTemplate = path.resolve('src/templates/post-template.tsx')
const tagTemplate = path.resolve('src/templates/tag-template.tsx')
const result = await graphql(`
{
postsRemark: allMdx (sort: {frontmatter: {date: DESC}}) {
edges {
node {
tableOfContents(maxDepth: 5)
internal {
contentFilePath
}
frontmatter {
h1
date
title
description
lang
slug
category
}
}
}
}
tagsGroup: allMdx {
group(field: {frontmatter: {tags: SELECT}}) {
fieldValue
}
}
}
`)
if (result.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`)
return
}
// Create post detail pages
const posts = result.data.postsRemark.edges
posts.forEach(({ node }, index) => {
const { lang, slug, category } = node.frontmatter
const prev = index === 0 ? false : posts[index - 1].node
const next = index === posts.length - 1 ? false : posts[index + 1].node
return createPage({
path: `${category}/${slug}/`,
component: `${blogPostTemplate}?__contentFilePath=${node.internal.contentFilePath}`,
context: { lang, slug, prev, next },
})
})
// Create tag pages
const tags = result.data.tagsGroup.group
tags.forEach(tag => {
createPage({
path: `/tags/${tag.fieldValue.toLowerCase()}/`,
component: tagTemplate,
context: {
tag: tag.fieldValue,
},
})
})
}
/*
const typeDefs = `
type SitePage implements Node @dontInfer {
context: CustomContext
}
type CustomContext {
prev: Boolean
next: Boolean
}
`
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
createTypes(typeDefs)
}
*/