-
Notifications
You must be signed in to change notification settings - Fork 1
/
introduction.js
80 lines (72 loc) · 2 KB
/
introduction.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
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 = 'introduction';
const sortingArray = findSortingArrays(category, siteStructure);
const query = graphql`
query IntroductionIndexQuery {
allMarkdownRemark(
filter: {
frontmatter: {
category: {
in: [
"introduction"
"introduction-getting-started"
"introduction-templates"
]
}
}
}
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 IntroductionPage = () => {
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 IntroductionPage;