-
Notifications
You must be signed in to change notification settings - Fork 1
/
design-toolkit.js
70 lines (62 loc) · 1.84 KB
/
design-toolkit.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
import React from 'react';
import { StaticQuery, graphql } from 'gatsby';
import { dev, siteStructure } from '../config';
import { findSortingArrays } from '../util/navigation';
import { ArticleIndexPage } from '../components';
const category = 'design-toolkit';
const sortingArray = findSortingArrays(category, siteStructure);
const query = graphql`
query DesignToolkitIndexQuery {
allMarkdownRemark(
filter: { frontmatter: { category: { in: ["design-toolkit"] } } }
sort: [{ frontmatter: { category: ASC } }, { frontmatter: { slug: ASC } }]
) {
edges {
node {
frontmatter {
title
slug
category
updated
ingress
published
}
}
}
}
}
`;
const byArrayOfSlugs = sortingArray => (a, b) => {
const indexA = sortingArray.indexOf(a.slug);
const indexB = sortingArray.indexOf(b.slug);
// If sorting array doesn't contain slug,
// we'll push it to the end of the array.
const defaultPlacement = sortingArray.length;
const i1 = indexA > -1 ? indexA : defaultPlacement;
const i2 = indexB > -1 ? indexB : defaultPlacement;
return i1 - i2;
};
const DesignToolkitPage = () => {
return (
<StaticQuery
query={query}
render={data => {
const edges = data.allMarkdownRemark
? data.allMarkdownRemark.edges
: [];
const articles = edges
.reduce((result, edge) => {
const { frontmatter } = edge.node;
if (dev || frontmatter.published) {
return result.concat(frontmatter);
} else {
return result;
}
}, [])
.sort(byArrayOfSlugs(sortingArray));
return <ArticleIndexPage category={category} articles={articles} />;
}}
/>
);
};
export default DesignToolkitPage;