-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
96 lines (86 loc) · 2.25 KB
/
gatsby-node.js
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
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
// You can delete this file if you're not using it
const path = require(`path`)
const { createFilePath } = require(`gatsby-source-filesystem`)
const { getUrlFriendlyName } = require(path.resolve(
"./src/utils/category-url-conversion.jsx"
))
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const articleTemplate = path.resolve(`./src/templates/article.jsx`)
const projectTemplate = path.resolve(`./src/templates/project.jsx`)
const snippetTemplate = path.resolve(`./src/templates/snippet.jsx`)
const result = await graphql(`
query {
allMarkdownRemark {
edges {
node {
frontmatter {
template
slug
category
published
}
}
}
tags: group(field: frontmatter___tags) {
fieldValue
totalCount
field
}
}
}
`)
const allMarkdown = result.data.allMarkdownRemark.edges
const articles = allMarkdown.filter(
({ node }) =>
node.frontmatter.template == "article" &&
node.frontmatter.published != false
)
const snippets = allMarkdown.filter(
({ node }) =>
node.frontmatter.template == "snippet" &&
node.frontmatter.published != false
)
const projects = allMarkdown.filter(
({ node }) =>
node.frontmatter.template == "project" &&
node.frontmatter.published != false
)
articles.forEach(article => {
const slug = article.node.frontmatter.slug
createPage({
path: `articles/${slug}`,
component: articleTemplate,
context: {
slug: slug,
},
})
})
projects.forEach(project => {
const slug = project.node.frontmatter.slug
createPage({
path: `projects/${slug}`,
component: projectTemplate,
context: {
slug: slug,
},
})
})
snippets.forEach(snippet => {
const slug = snippet.node.frontmatter.slug
const category = snippet.node.frontmatter.category
createPage({
path: `snippets/${slug}`,
component: snippetTemplate,
context: {
slug: slug,
// category: category,
},
})
})
}