Skip to content

Commit 55f9a9d

Browse files
committed
feat: Refactor Gatsby link out of components
1 parent b778081 commit 55f9a9d

File tree

6 files changed

+52
-39
lines changed

6 files changed

+52
-39
lines changed

components/legacy-components/src/article-card/article-card.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
1-
import { Link } from "gatsby"
1+
import { Link } from "@reach/router"
22
import { format as formatDate } from 'date-fns'
33
import React from "react"
44
import ResponsiveImage from '../responsive-image'
55

6-
export default function articleCard({article, withBody = true, withImage = true, withDate = true}) {
6+
export default function articleCard({ article, linkImplementation = Link, withBody = true, withImage = true, withDate = true }) {
77

88
const date = new Date(article.date)
9+
const LinkImplementation = linkImplementation
910

1011
return (
1112
<div className="alex-card">
1213

1314
<div className="alex-card__content--container">
1415

1516
<div className="alex-card__title">
16-
<h3><Link to={ article.slug }>{ article.title }</Link></h3>
17+
<h3><LinkImplementation to={article.slug}>{article.title}</LinkImplementation></h3>
1718
</div>
1819

1920
{(withBody !== false) ?
2021
<div className="alex-card__abstract">
21-
<p>
22-
{ article.content.excerpt }
23-
</p>
24-
</div>
25-
:null}
22+
<p>
23+
{article.content.excerpt}
24+
</p>
25+
</div>
26+
: null}
2627

2728
{(withDate !== false) ?
2829
<div className="alex-card__timetamp">
2930
<span className="dateline">
30-
<time dateTime={date.toISOString()}>{ formatDate(date, "d MMM yyyy") }</time>
31+
<time dateTime={date.toISOString()}>{formatDate(date, "d MMM yyyy")}</time>
3132
</span>
3233
</div>
33-
:null}
34+
: null}
3435

3536
</div>
3637

3738
{(withImage !== false && article.image && article.image.thumbnail) ?
3839
<div className="alex-card__image">
39-
<ResponsiveImage src={ article.image.thumbnail } width={ 400 } />
40+
<ResponsiveImage src={article.image.thumbnail} width={400} />
4041
</div>
41-
:null}
42+
: null}
4243

4344
</div>
4445
)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import "./article-card.scss";
22
import ArticleCard from "./article-card"
3-
export {ArticleCard}
3+
export { ArticleCard }
44
export default ArticleCard

components/legacy-components/src/header/header.js

+2
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,13 @@ class Header extends Component {
176176
Header.propTypes = {
177177
siteTitle: PropTypes.string,
178178
image: PropTypes.string,
179+
location: PropTypes.object
179180
}
180181

181182
Header.defaultProps = {
182183
siteTitle: `Alex Wilson`,
183184
image: null,
185+
location: { pathname: "/" }
184186
}
185187

186188
export default Header
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
import { ArticleCard } from '@alexwilson/legacy-components/src/article-card';
3+
import { Link } from 'gatsby';
4+
5+
export default (props) => <ArticleCard linkImplementation={Link} {...props} />

services/personal-website/src/components/related-articles.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react'
22
import { useStaticQuery, graphql } from "gatsby"
3-
import ArticleCard from "@alexwilson/legacy-components/src/article-card"
3+
import ArticleCard from "./article-card"
44

5-
export default ({article: currentArticle}) => {
5+
export default ({ article: currentArticle }) => {
66
const data = useStaticQuery(graphql`
77
query RelatedArticles {
88
posts: allContent(
@@ -38,7 +38,7 @@ export default ({article: currentArticle}) => {
3838
if (article.contentId === currentArticle.contentId) continue;
3939
if (relatedArticles.size >= maxArticles) break;
4040

41-
const isWeeknote = (article.topics.filter(({topic}) => topic == "weeknotes").length > 0)
41+
const isWeeknote = (article.topics.filter(({ topic }) => topic == "weeknotes").length > 0)
4242

4343
// Hack to reduce relevance of weeknotes.
4444
if (granularity >= 1 && isWeeknote) {
@@ -65,7 +65,7 @@ export default ({article: currentArticle}) => {
6565
<>
6666
{Array.from(relatedArticles.values()).map(
6767
(article) => <ArticleCard key={article.contentId} article={article} withBody={false} withDate={false}
68-
/>)}
68+
/>)}
6969
</>
7070
)
7171
}

services/personal-website/src/pages/index.js

+27-22
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
import React from "react"
22
import { graphql } from 'gatsby'
33

4-
import ArticleCard from "@alexwilson/legacy-components/src/article-card"
4+
import ArticleCard from "../components/article-card"
55
import Layout from "../components/layout"
66
import SEO from "../components/seo"
77

88
const IndexPage = ({ data, location }) => (
99
<Layout location={location}>
10-
<SEO title="Home" keywords={[`gatsby`, `application`, `react`]} />
10+
<SEO title="Home" />
1111
<div className="alex-home">
12-
<section className="alex-home__section">
13-
</section>
14-
<section className="alex-home__section">
15-
<h2><a className="heading" href="/blog/">Latest Writing</a></h2>
16-
<div className="alex-home__tilestack">
17-
{data.allButWeeknotes.nodes.map((node) =>
18-
<div key={node.contentId} className="alex-home__tilestack-item">
19-
<ArticleCard article={node} withImage={false} withDate={false} />
20-
</div>
21-
)}
12+
<section className="alex-home__section">
13+
</section>
14+
<section className="alex-home__section">
15+
<h2><a className="heading" href="/blog/">Latest Writing</a></h2>
16+
<div className="alex-home__tilestack">
17+
{data.allButWeeknotes.nodes.map((node) =>
18+
<div key={node.contentId} className="alex-home__tilestack-item">
19+
<ArticleCard article={node} withImage={false} withDate={false} />
2220
</div>
23-
</section>
24-
<section className="alex-home__section">
25-
<h2><a className="heading" href="/topic/weeknotes">Latest Notes</a></h2>
26-
<div className="alex-home__tilestack">
27-
{data.onlyWeeknotes.nodes.map((node) =>
28-
<div key={node.contentId} className="alex-home__tilestack-item">
29-
<ArticleCard article={node} withImage={false} withDate={false} />
30-
</div>
31-
)}
21+
)}
22+
</div>
23+
</section>
24+
<section className="alex-home__section">
25+
<h2><a className="heading" href="/topic/weeknotes">Latest Notes</a></h2>
26+
<div className="alex-home__tilestack">
27+
{data.onlyWeeknotes.nodes.map((node) =>
28+
<div key={node.contentId} className="alex-home__tilestack-item">
29+
<ArticleCard article={node} withImage={false} withDate={false} />
3230
</div>
33-
</section>
31+
)}
32+
</div>
33+
</section>
3434
</div>
3535
</Layout>
3636
)
@@ -71,6 +71,11 @@ export const query = graphql`
7171
}
7272
}
7373
}
74+
site {
75+
siteMetadata {
76+
siteUrl
77+
}
78+
}
7479
}
7580
7681
`

0 commit comments

Comments
 (0)