Skip to content

Commit e5de64b

Browse files
committed
Add support for attribution on header image
Previously attribution was defined, but wasn't being display anywhere.
1 parent c6d9632 commit e5de64b

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed

src/app/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export interface ArticleSummary {
3030
}
3131
}
3232

33+
export interface Attribution {
34+
author: string
35+
url: string
36+
}
37+
3338
export interface Article {
3439
id: string
3540
body: string
@@ -38,6 +43,7 @@ export interface Article {
3843
title: string
3944
date: string
4045
cover: FluidImage
46+
attribution: Attribution | null
4147
}
4248
}
4349

src/components/Article.treat.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ globalStyle(`${article} strong`, (theme) => ({
2222
color: theme.primary,
2323
fontWeight: 550,
2424
}))
25+
26+
export const attribution = style((theme) => ({
27+
// Typography
28+
color: theme.typeColourLight,
29+
}))

src/components/Article.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { FunctionComponent } from 'react'
44
import { useStyles } from 'react-treat'
55
import { MDXProvider } from '@mdx-js/react'
66
import { MDXRenderer } from 'gatsby-plugin-mdx'
7-
import { FluidImage } from '../app/types'
7+
import { FluidImage, Attribution } from '../app/types'
88
import * as styleRefs from './Article.treat'
99

1010
import Figure from './Article/Figure'
@@ -23,6 +23,7 @@ const components: ComponentMap = {
2323

2424
interface ArticleProps {
2525
coverImage: FluidImage
26+
attribution: Attribution
2627
title: string
2728
date: string
2829
excerpt: string
@@ -44,6 +45,19 @@ function Article(props: ArticleProps) {
4445
</MDXProvider>
4546

4647
<ThanksForReading />
48+
49+
{props.attribution !== null && (
50+
<p className={styles.attribution}>
51+
Cover image by{' '}
52+
<a
53+
href={props.attribution.url}
54+
target="_blank"
55+
rel="noopener noreferer"
56+
>
57+
{props.attribution.author}
58+
</a>
59+
</p>
60+
)}
4761
</Wrapper>
4862
</article>
4963
)

src/components/Article/Header.treat.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
import { style } from 'treat'
44

55
export const image = style((theme) => ({
6-
// Box model
7-
marginBottom: '4rem',
8-
96
// Visuals
107
backgroundColor: theme.grey80,
118
borderRadius: '3px',
@@ -27,8 +24,8 @@ export const title = style({
2724
'(min-width: 600px)': {
2825
fontSize: '3.052rem',
2926
lineHeight: '1.15 !important',
30-
}
31-
}
27+
},
28+
},
3229
})
3330

3431
export const date = style((theme) => ({

src/components/Article/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react'
44
import Img from 'gatsby-image'
55
import { useStyles } from 'react-treat'
66

7-
import { FluidImage } from '../../app/types'
7+
import { FluidImage, Attribution } from '../../app/types'
88
import * as styleRefs from './Header.treat'
99

1010
interface HeaderProps {

src/templates/Article.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function Container(props: ContainerProps) {
2323
<Layout>
2424
<Article
2525
coverImage={article.frontmatter.cover}
26+
attribution={article.frontmatter.attribution}
2627
title={article.frontmatter.title}
2728
date={article.frontmatter.date}
2829
excerpt={article.excerpt}
@@ -50,6 +51,10 @@ export const pageQuery = graphql`
5051
}
5152
}
5253
}
54+
attribution {
55+
author
56+
url
57+
}
5358
}
5459
}
5560
}

0 commit comments

Comments
 (0)