-
Notifications
You must be signed in to change notification settings - Fork 1
/
category.js
86 lines (78 loc) · 2.13 KB
/
category.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
import React from "react";
import { graphql } from "gatsby";
import Layout from "../../components/layout/Layout";
import SEO from "../../components/SEO";
import { injectIntl } from "gatsby-plugin-intl";
import Section from "../../components/section/Section";
import BlogPosts from "../../components/blog/list/List";
import MissingTranslation from "../../components/MissingTranslation";
export const pageQuery = graphql`
query BlogPostsByCategory($slug: String!) {
sk: allMdx(
filter: {
fields: { categorySlug: { eq: $slug }, language: { eq: "sk" } }
}
) {
edges {
node {
frontmatter {
post_title
post_date(formatString: "D. MMM YYYY", locale: "sk")
post_category
}
fields {
slug
}
}
}
}
en: allMdx(
filter: {
fields: { categorySlug: { eq: $slug }, language: { eq: "en" } }
}
) {
edges {
node {
frontmatter {
post_title
post_date(formatString: "D. MMM YYYY", locale: "en")
post_category
}
fields {
slug
}
}
}
}
}
`;
const BlogCategoryTemplate = ({ data, pageContext, intl }) => {
const language = intl.locale;
if (data[language].edges.length === 0) {
return <MissingTranslation id={`/${language}${pageContext.slug}`} />;
}
const posts = data[language].edges;
const { slug } = pageContext;
const category = posts[0].node.frontmatter.post_category;
return (
<Layout
backTo={{
to: "/blog/",
title: `${intl.formatMessage({ id: "backto" })} ${intl.formatMessage({
id: "backto.blog",
})}`,
}}
>
<SEO
lang={language}
title={`${category} — ${intl.formatMessage({ id: "page.blog.title" })}`}
slug={slug}
description={`${intl.formatMessage({
id: "page.category.description",
})}: ${category}`}
/>
<Section title={category} render={() => <BlogPosts data={posts} />} />
</Layout>
);
};
export default injectIntl(BlogCategoryTemplate);