-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
142 lines (132 loc) · 3.76 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* 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 _ = require("lodash")
const path = require(`path`)
const { paginate } = require("gatsby-awesome-pagination")
exports.onCreateWebpackConfig = ({
stage,
rules,
loaders,
plugins,
actions,
}) => {
actions.setWebpackConfig({
module: {
rules: [
{
test: /\.gltf$/,
use: [
`url-loader`,
],
},
],
},
})
}
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
return new Promise((resolve, reject) => {
const blogPost = path.resolve(`./src/templates/blog-post.js`)
const workPost = path.resolve(`./src/templates/project-post.js`)
const tagTemplate = path.resolve(`src/templates/tags-template.js`)
resolve(
graphql(
`
{
allContentfulBlog(sort: {order: DESC, fields: createdAt}) {
edges {
node {
title
slug
tags
excerpt {
excerpt
}
}
}
}
allContentfulWorks(sort: {order: DESC, fields: createdAt}) {
edges {
node {
id
title
slug
}
}
}
}
`
).then(result => {
if (result.errors) {
console.log(result.errors)
reject(result.errors)
}
paginate({
createPage,
items: result.data.allContentfulBlog.edges,
itemsPerPage: 24,
pathPrefix: "/blog",
component: path.resolve("src/templates/blog-archive.js"),
})
paginate({
createPage,
items: result.data.allContentfulWorks.edges,
itemsPerPage: 88,
pathPrefix: "/colaboraciones",
component: path.resolve("src/templates/project-archive.js"),
})
const posts = result.data.allContentfulBlog.edges
const works = result.data.allContentfulWorks.edges
posts.forEach((post, index) => {
createPage({
path: `/blog/${post.node.slug}/`,
component: blogPost,
context: {
slug: post.node.slug,
prev: index === 0 ? null : posts[index - 1].node,
next: index === posts.length - 1 ? null : posts[index + 1].node,
title: post.node.title,
tagline: post.node.excerpt.excerpt,
},
})
})
works.forEach((work, index) => {
createPage({
path: `/colaboraciones/${work.node.slug}/`,
component: workPost,
context: {
slug: work.node.slug,
prev: index === 0 ? null : works[index - 1].node,
next: index === works.length - 1 ? null : works[index + 1].node,
},
})
})
// create Tags pages
// pulled directly from https://www.gatsbyjs.org/docs/adding-tags-and-categories-to-blog-posts/#add-tags-to-your-markdown-files
let tags = []
// Iterate through each post, putting all found tags into `tags`
_.each(posts, edge => {
if (_.get(edge, "node.tags")) {
tags = tags.concat(edge.node.tags)
}
})
// Eliminate duplicate tags
tags = _.uniq(tags)
// Make tag pages
tags.forEach(tag => {
createPage({
path: `/etiquetas/${_.kebabCase(tag)}/`,
component: tagTemplate,
context: {
tag,
},
})
})
})
)
})
}