-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
53 lines (50 loc) · 1.3 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
const path = require(`path`)
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
return graphql(`
{
allMysqlLists(sort: { fields: create_time, order: DESC }) {
edges {
node {
title
description
menu
source
href
create_time(formatString: "MM-DD-YYYY")
href_hash
}
}
}
}
`).then(result => {
const posts = result.data.allMysqlLists.edges
posts.forEach(({ node }) => {
createPage({
// Decide URL structure
path: `/posts/${node.href_hash}/`,
// path to template
component: path.resolve(`./src/templates/blog-post.js`),
context: {
// This is the $slug variable
// passed to blog-post.js
slug: node.href_hash,
},
})
})
const postsPerPage = 30
const numPages = Math.ceil(posts.length / postsPerPage)
Array.from({ length: numPages }).forEach((_, i) => {
createPage({
path: i === 0 ? `/` : `/${i + 1}`,
component: path.resolve("./src/templates/blog-list.js"),
context: {
limit: postsPerPage,
skip: i * postsPerPage,
numPages,
currentPage: i + 1,
},
})
})
})
}