-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy patharticles.js
98 lines (92 loc) · 2.75 KB
/
articles.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
94
95
96
97
98
import React from "react"
import { graphql } from "gatsby"
import { Layout } from "../components/layout";
const Articles = (props) => {
const { data } = props;
const articles = data.allKontentItemArticle.group.map(articleItem => {
const variants = articleItem
.nodes
.sort((a, b) => a.preferred_language < b.preferred_language ? 1 : -1)
.map(variant => {
const tags = variant.elements.tags.value.map(tag => (
<div key={tag.id} style={{ padding: ".2em", margin: ".3em", background: "cyan" }}>{tag.elements.title.value}</div>
));
return (<div key={variant.id} style={{ padding: ".5em", margin: ".5em", background: "silver" }}>
<div><strong>({variant.preferred_language}{variant.preferred_language !== variant.system.language ? ` -> ${variant.system.language}` : null})</strong></div>
<div><i>Date:</i> {variant.elements.date.value}{variant.elements.date.display_timezone && ` (${variant.elements.date.display_timezone})`}</div>
<div>
<i>Title:</i> {variant.elements.title.value}
</div>
<div><i>Description:</i> {variant.elements.description.value}</div>
<div style={{ padding: "0.5em", display: "flex", flexWrap: "wrap" }}>{tags}</div>
</div>
)
});
return (
<article key={articleItem.nodes[0].id} style={{ width: "350px", padding: "1em", margin: "0.3em", border: "solid 1px" }}>
Article:
<ul>
<li>Node ID: {articleItem.nodes[0].id}</li>
<li>System ID: {articleItem.nodes[0].system.id}</li>
<li>{articleItem.nodes[0].system.name}</li>
<li>{articleItem.nodes[0].system.codename}</li>
<li>{articleItem.nodes[0].system.last_modified}</li>
</ul>
{variants}
</article>
);
});
return (
<Layout>
<div style={{ display: "flex", flexWrap: "wrap" }}>
{articles}
</div>
</Layout>
)
}
export const query = graphql`
{
allKontentItemArticle(sort: {system: {last_modified: DESC}}) {
totalCount
group(field: {system: {id: SELECT}}) {
nodes {
id
preferred_language
system {
last_modified
language
codename
id
name
type
}
elements {
title {
value
}
date {
value
display_timezone
}
description {
value
}
tags {
value {
... on kontent_item_tag {
id
elements {
title {
value
}
}
}
}
}
}
}
}
}
}
`
export default Articles