-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
93 lines (80 loc) · 1.81 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
const path = require("path");
const {paginate} = require('gatsby-awesome-pagination');
exports.createPages = async ({graphql, actions: {createPage}}) => {
const query = await graphql(`
query {
repos: allRepo {
topics: group(field: {topics: SELECT}) {
fieldValue
totalCount
}
}
}
`);
const topics = query.data.repos.topics.map(topic => {
return {
name: topic.fieldValue,
count: topic.totalCount
}
});
topics.sort((a,b) => {
if (b.count - a.count !== 0) {
return b.count - a.count;
}
return a.name.localeCompare(b.name);
});
createPage({
path: `/technologies/`,
component: path.resolve('./src/templates/technologies.jsx'),
context: {
topics,
}
});
const data = await graphql(`
{
allRepo(sort: [{isPinned: DESC}, {pushedAt: DESC}]) {
nodes {
id
topics
}
}
}
`);
const repos = data.data.allRepo.nodes;
let topicArr = topics.map(t => t.name)
const topicsSet = new Set(topicArr);
topicArr = [...topicsSet];
paginate({
createPage,
items: repos,
component: path.resolve('./src/templates/projects.jsx'),
itemsPerPage: 6,
pathPrefix: '/projects'
});
topicArr.forEach(topic => {
createPage({
path: `/technologies/${topic}/`,
component: path.resolve('./src/templates/technology.jsx'),
context: {
topic,
}
});
});
const dataC = await graphql(`
{
allContrib(sort: [{totalContribs: DESC}, {name: ASC}]) {
nodes {
id
}
}
}
`);
const contribs = dataC.data.allContrib.nodes;
paginate({
createPage,
items: contribs,
component: path.resolve('./src/templates/contributions.jsx'),
itemsPerPage: 6,
pathPrefix: '/contributions'
});
}