Skip to content

Commit 9c76ba3

Browse files
committed
Add passive redirect to old cancer pages.
1 parent 33109f2 commit 9c76ba3

File tree

7 files changed

+128
-5
lines changed

7 files changed

+128
-5
lines changed

gatsby-config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ module.exports = {
6969
respectDNT: true
7070
}
7171
}
72+
},
73+
{
74+
resolve: `gatsby-plugin-meta-redirect`
7275
}
7376
]
7477
}

src/components/Link.styles.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import styled, { css } from 'styled-components'
33

44
import { $theme } from '../styles/theme'
55

6-
export const linkStyles = css`
6+
type LinkProps = {
7+
variant?: 'inline' | 'block'
8+
}
9+
10+
const linkInlineStyles = css`
711
color: ${$theme.color.link};
812
text-underline-offset: 3px;
913
text-decoration-thickness: 2px;
@@ -13,10 +17,44 @@ export const linkStyles = css`
1317
}
1418
`
1519

20+
const linkBlockStyles = css`
21+
display: inline-block;
22+
text-decoration: none;
23+
background-color: ${$theme.color.primary}dd;
24+
padding: 1em 1.5em;
25+
color: ${$theme.color.background};
26+
border-radius: 0.2em;
27+
font-size: 1.2rem;
28+
transition: ${$theme.transition.default};
29+
30+
&:hover,
31+
&:focus {
32+
background-color: ${$theme.color.primary}ff;
33+
}
34+
35+
&:active {
36+
transition: none;
37+
background-color: ${$theme.color.primary}dd;
38+
}
39+
`
40+
41+
export const linkStyles = css<LinkProps>`
42+
${(props) => props.variant === 'inline' && linkInlineStyles}
43+
${(props) => props.variant === 'block' && linkBlockStyles}
44+
`
45+
1646
export const ExternalLink = styled.a`
1747
${linkStyles};
1848
`
1949

50+
ExternalLink.defaultProps = {
51+
variant: 'inline'
52+
}
53+
2054
export const InternalLink = styled(GatsbyLink)`
2155
${linkStyles};
2256
`
57+
58+
InternalLink.defaultProps = {
59+
variant: 'inline'
60+
}

src/components/SEO.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type SEOProps = {
2121
name: string
2222
url?: string
2323
}>
24+
noIndex?: boolean
2425
}
2526

2627
export const SEO: React.FC<SEOProps> = ({
@@ -30,7 +31,8 @@ export const SEO: React.FC<SEOProps> = ({
3031
image,
3132
title,
3233
pathname,
33-
breadcrumbs = []
34+
breadcrumbs = [],
35+
noIndex = false
3436
}) => {
3537
const { site } = useStaticQuery(
3638
graphql`
@@ -131,6 +133,16 @@ export const SEO: React.FC<SEOProps> = ({
131133
}
132134
]
133135
)
136+
.concat(
137+
noIndex
138+
? [
139+
{
140+
name: 'robots',
141+
content: 'noindex'
142+
}
143+
]
144+
: []
145+
)
134146
.concat(meta as any)}
135147
script={
136148
breadcrumbs.length > 0

src/components/Typography.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { up } from 'styled-breakpoints'
22
import styled from 'styled-components'
33

44
import { $theme } from '../styles/theme'
5-
65
import { linkStyles } from './Link.styles'
76

87
export const Heading1 = styled.h1`
@@ -25,7 +24,7 @@ export const PageTitle = styled.h1`
2524
font-size: ${$theme.fontSize.l2}rem;
2625
font-weight: ${$theme.fontWeight.black};
2726
line-height: 1em;
28-
margin: 0.2em 0;
27+
margin: 0.2em 0 2rem 0;
2928
3029
${up('tablet')} {
3130
font-size: ${$theme.fontSize.l1}rem;
@@ -80,3 +79,7 @@ export const TextBlock = styled.div`
8079
border-left: ${$theme.color.copyLight} solid 2px;
8180
}
8281
`
82+
83+
export const InlineCenter = styled.div`
84+
text-align: center;
85+
`

src/layouts/MainLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const MainLayout: React.FC = ({ children }) => {
1414
<S.Container>
1515
<GlobalStyles />
1616
<Header />
17-
{children}
17+
<main>{children}</main>
1818
<Footer />
1919
</S.Container>
2020
</ThemeProvider>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
date: 2021-08-24T01:16:03-04:00
3+
title: 'TBD'
4+
slug: /lymphoma/2021-08-24
5+
---

src/pages/cancer/[...path].tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import * as React from 'react'
2+
import { graphql, PageProps } from 'gatsby'
3+
4+
import { MainLayout } from '../../layouts/MainLayout'
5+
import { InlineCenter, PageTitle } from '../../components/Typography'
6+
import { InternalLink } from '../../components/Link.styles'
7+
import NotFoundPage from '../404'
8+
import { SEO } from '../../components/SEO'
9+
10+
type CancerCatchAllPageDataProps = {
11+
allMarkdownRemark: {
12+
edges: Array<{
13+
node: {
14+
frontmatter: {
15+
slug: string
16+
}
17+
}
18+
}>
19+
}
20+
}
21+
22+
const CancerCatchAllPage: React.FC<PageProps<CancerCatchAllPageDataProps>> = (
23+
props
24+
) => {
25+
const post = props.data.allMarkdownRemark.edges.find(
26+
(e) => e.node.frontmatter.slug.split('/').pop() === props.path
27+
)
28+
29+
const slug = post?.node.frontmatter.slug
30+
31+
if (!slug) {
32+
return <NotFoundPage />
33+
}
34+
35+
return (
36+
<MainLayout>
37+
<SEO title="This page have been moved" noIndex />
38+
<PageTitle>This page have been moved</PageTitle>
39+
<InlineCenter>
40+
<InternalLink variant="block" to={slug}>
41+
Go to new location
42+
</InternalLink>
43+
</InlineCenter>
44+
</MainLayout>
45+
)
46+
}
47+
48+
export default CancerCatchAllPage
49+
50+
export const pageQuery = graphql`
51+
query {
52+
allMarkdownRemark {
53+
edges {
54+
node {
55+
frontmatter {
56+
slug
57+
}
58+
}
59+
}
60+
}
61+
}
62+
`

0 commit comments

Comments
 (0)