-
-
Notifications
You must be signed in to change notification settings - Fork 550
/
resolver-templates.ts
40 lines (33 loc) · 1.02 KB
/
resolver-templates.ts
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
import type { IGridItem } from "./modify-grid"
// Only return nodes with the type "MdxPage"
export function onlyPages(data: IGridItem[]) {
return data.filter((p) => p.__typename === `MdxPage`)
}
// Only return nodes with the type "MdxProject"
export function onlyProjects(data: IGridItem[]) {
return data.filter((p) => p.__typename === `MdxProject`)
}
// Only return nodes that match the slugs defined in the given array of slugs
export function filterBySlug(data: IGridItem[], slugFilter: string[]) {
return data.filter((d) => slugFilter.includes(d.slug))
}
function random(seed: number) {
// eslint-disable-next-line no-param-reassign
const x = Math.sin(seed++) * 10000
return x - Math.floor(x)
}
export function shuffle(originalData: IGridItem[], seed = 1) {
const data = [...originalData]
let m = data.length
let t
let i
while (m) {
i = Math.floor(random(seed) * m--)
t = data[m]
data[m] = data[i]
data[i] = t
// eslint-disable-next-line no-param-reassign
++seed
}
return data
}