-
-
Notifications
You must be signed in to change notification settings - Fork 767
/
Copy pathblog-article.tsx
103 lines (97 loc) · 3 KB
/
blog-article.tsx
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
99
100
101
102
103
import { graphql } from "gatsby";
import { GatsbyImage } from "gatsby-plugin-image";
import { MDXRenderer } from "gatsby-plugin-mdx";
import React, { FC } from "react";
import styled from "styled-components";
import {
ArticleContent,
ArticleHeader,
ArticleHeaderVideoContainer,
ArticleTitle,
ArticleVideo,
} from "@/components/article-elements";
import { ArticleLayout } from "@/components/layout";
import { BlogArticleFragment } from "@/graphql-types";
import { ArticleTableOfContent } from "./article-table-of-content";
import { BlogArticleMetadata } from "./blog-article-metadata";
import { BlogArticleNavigation } from "./blog-article-navigation";
import { BlogArticleSharebar } from "./blog-article-sharebar";
import { BlogArticleTags } from "./blog-article-tags";
import { ResponsiveArticleMenu } from "./responsive-article-menu";
export interface BlogArticleProps {
readonly data: BlogArticleFragment;
}
export const BlogArticle: FC<BlogArticleProps> = ({ data }) => {
const { mdx } = data;
const { fields, frontmatter, body } = mdx!;
const title = frontmatter!.title!;
const existingTags: string[] = frontmatter!.tags!
? (frontmatter!.tags!.filter((tag) => tag && tag.length > 0) as string[])
: [];
const featuredImage =
frontmatter!.featuredImage?.childImageSharp?.gatsbyImageData;
const featuredVideoId = frontmatter!.featuredVideoId;
return (
<ArticleLayout
navigation={
<BlogArticleNavigation data={data} selectedPath={fields?.slug ?? ""} />
}
aside={<ArticleTableOfContent data={data.mdx!} />}
>
<ArticleHeader>
<ResponsiveArticleMenu />
{featuredVideoId && (
<ArticleHeaderVideoContainer>
<ArticleVideo videoId={featuredVideoId} />
</ArticleHeaderVideoContainer>
)}
{featuredImage && !featuredVideoId && (
<GatsbyImage image={featuredImage} alt={title} />
)}
<ArticleTitle>{title}</ArticleTitle>
<Metadata>
<BlogArticleMetadata data={mdx!} />
<BlogArticleSharebar data={data} tags={existingTags} />
</Metadata>
<BlogArticleTags tags={existingTags} />
</ArticleHeader>
<ArticleContent>
<MDXRenderer>{body}</MDXRenderer>
</ArticleContent>
</ArticleLayout>
);
};
export const BlogArticleGraphQLFragment = graphql`
fragment BlogArticle on Query {
mdx(frontmatter: { path: { eq: $path } }) {
excerpt
fields {
slug
}
frontmatter {
featuredImage {
childImageSharp {
gatsbyImageData(layout: CONSTRAINED, width: 800, quality: 100)
}
}
featuredVideoId
path
title
description
...BlogArticleTags
}
body
...ArticleSections
...BlogArticleMetadata
}
...BlogArticleNavigation
...BlogArticleSharebar
}
`;
const Metadata = styled.div`
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
margin-bottom: 24px;
`;