-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.js
54 lines (52 loc) · 1.34 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
const path = require('path');
const createPaginatedPages = require('gatsby-paginate');
exports.createPages = ({ graphql, actions: { createPage } }) => {
return new Promise((resolve, reject) => {
graphql(`
{
posts: allWordpressPost(limit: 100) {
edges {
node {
id
slug
link
title
content
timeDate: date
date(formatString: "DD MMM YYYY")
excerpt
author {
id
name
avatar_urls {
wordpress_48
}
}
}
}
}
}
`).then(result => {
createPaginatedPages({
pageLength: 5,
edges: result.data.posts.edges,
createPage: createPage,
pageTemplate: 'src/templates/home.js',
buildPath: (index, pathPrefix) =>
index > 1 ? `${pathPrefix}/${index}` : `/${pathPrefix}`
});
result.data.posts.edges.map(({ node }) => {
const url = new URL(node.link) || {};
createPage({
path: url.pathname,
component: path.resolve('./src/templates/posts.js'),
context: {
slug: url.pathname,
...node
}
});
resolve();
});
});
});
};