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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
const path = require(`path`);
exports.sourceNodes = ({ actions }) => {
const { createTypes } = actions;
const typeDefs = `
type Term {
power: Int!
coeff: String!
}
type Element {
raw: String
poly: [Term]
}
enum FieldType {
Prime
Binary
Extension
}
type Field {
type: FieldType
p: String
poly: [Term]
base: String
degree: Int
bits: Int
}
type Point {
x: Element
y: Element
}
enum Form {
Weierstrass
Montgomery
Edwards
TwistedEdwards
}
type Params @dontInfer {
a: Element
b: Element
c: Element
d: Element
}
type Curve implements Node {
name: String!
category: String!
desc: String
oid: String
field: Field
form: Form
params: Params
generator: Point
order: String!
cofactor: String!
aliases: [String]
}
type Category implements Node {
name: String!
desc: String
}
`;
createTypes(typeDefs);
};
exports.onCreateNode = ({
node,
actions,
getNode,
createNodeId,
createContentDigest
}) => {
const { createNode, createParentChildLink } = actions;
if (node.internal.type !== `CurvesJson`) {
return;
}
const fileNode = getNode(node.parent);
if (fileNode.base === "schema.json") {
return;
}
const catId = createNodeId(`${node.id} >>> Category`);
const catContentDigest = createContentDigest(node);
createNode({
name: node.name,
desc: node.desc,
id: catId,
parent: node.id,
children: [],
internal: {
type: `Category`,
contentDigest: catContentDigest,
description: `Category`
}
});
createParentChildLink({ parent: fileNode, child: node });
node.curves.forEach(curve => {
const curveId = createNodeId(
`${node.id} >>> ${node.name} >>> ${curve.name}`
);
const curveContentDigest = createContentDigest(curve);
createNode({
...curve,
id: curveId,
parent: catId,
children: [],
internal: {
type: `Curve`,
contentDigest: curveContentDigest,
description: `Curve`
}
});
createParentChildLink({ parent: getNode(catId), child: getNode(curveId) });
});
};
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const result = await graphql(`
query {
allCategory {
nodes {
name
children {
... on Curve {
name
}
}
parent {
parent {
... on File {
relativeDirectory
}
}
}
}
}
}
`);
result.data.allCategory.nodes.forEach(category => {
createPage({
path: category.parent.parent.relativeDirectory,
component: path.resolve(`./src/templates/category.js`),
context: {
name: category.name
}
});
category.children.forEach(curve => {
createPage({
path: path.join(category.parent.parent.relativeDirectory, curve.name),
component: path.resolve(`./src/templates/curve.js`),
context: {
name: curve.name
}
});
});
});
};
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === "build-javascript") {
// turn off source-maps
actions.setWebpackConfig({
devtool: false
});
} else if (stage === "build-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /pseudocode/,
use: loaders.null()
}
]
}
});
}
};
|