-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathblog.js
More file actions
136 lines (130 loc) · 3.72 KB
/
blog.js
File metadata and controls
136 lines (130 loc) · 3.72 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import React, { Fragment } from 'react';
import { Link, graphql } from 'gatsby';
import Image from 'gatsby-image';
import Footer from '../components/Footer';
import MainNav from '../components/MainNav';
import Sidebar from '../components/Sidebar';
import SEO from '../components/SEO';
import { buildAuthorIndex } from '../utils/authors';
export default function BlogPage(props) {
const { posts, authors } = props.data;
const authorIndex = buildAuthorIndex(authors);
return (
<Fragment>
<SEO
title="Blog"
description="Articles, tutorials and opinions from the community, everyone is welcome to contribute."
/>
<MainNav showLogo title="Blog" />
<div className="container py-16 lg:flex lg:flex-row">
<main className="lg:w-3/4">
{posts.edges.map(({ node }) => (
<PostExcerpt
key={node.id}
data={node.frontmatter}
author={authorIndex[node.frontmatter.author]}
excerpt={node.excerpt}
fields={node.fields}
/>
))}
</main>
<Sidebar />
</div>
<Footer />
</Fragment>
);
}
function PostExcerpt({ author, data, excerpt, fields }) {
return (
<article className="mb-16 md:flex">
<div className="mb-2 md:w-1/3 md:mb-0">
{data.image && (
<Link to={fields.slug}>
<Image
fluid={data.image.childImageSharp.fluid}
style={{ maxHeight: '170px' }}
/>
</Link>
)}
</div>
<div className="md:w-2/3 md:pl-8">
<p className="mb-0">
{data.tags.map(tag => (
<span
key={tag}
className="inline-block mr-2 uppercase text-xs text-secondary-dark"
>
{tag}
</span>
))}
</p>
<h2 className="my-1 font-display text-2xl">
<Link to={fields.slug} className="hover:underline">
{data.title}
</Link>
</h2>
<p className="mb-1 font-body text-sm uppercase text-secondary-dark">
<a aria-label={author.frontmatter.name} href={author.frontmatter.link} className="hover:underline">{author.frontmatter.name}</a> <span className="inline-block mx-2">·</span>{' '}
{data.date} <span className="inline-block mx-2">·</span>{' '}
{fields.readingTime.text}
</p>
<p className="font-body text-base text-secondary-dark">{excerpt}</p>
</div>
</article>
);
}
export const postsQuery = graphql`
query {
posts: allMarkdownRemark(
filter: { fields: { slug: { regex: "/^/blog/.*/" } } }
sort: { order: DESC, fields: frontmatter___date }
) {
edges {
node {
frontmatter {
title
tags
author
date(formatString: "MMMM Do, YYYY")
image {
childImageSharp {
resize(width: 1500, height: 1500) {
src
}
fluid(maxWidth: 786) {
...GatsbyImageSharpFluid
}
}
}
}
id
excerpt(truncate: false)
fields {
slug
readingTime {
text
}
}
}
}
}
authors: allMarkdownRemark(
filter: { fields: { slug: { regex: "/^/authors/.*/" } } }
) {
edges {
node {
frontmatter {
name
avatar
about
link
}
id
fields {
slug
}
}
}
}
}
`;