Skip to content

Commit 59fd831

Browse files
committed
Don't fetch Medium posts anymore
1 parent 11895b9 commit 59fd831

File tree

4 files changed

+72
-175
lines changed

4 files changed

+72
-175
lines changed

packages/homepage/gatsby-node.js

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,6 @@ exports.createPages = async ({ graphql, actions }) => {
5151
toPath: '/',
5252
});
5353

54-
const blogsFromMedium = await graphql(`
55-
{
56-
allFeedMediumBlog {
57-
edges {
58-
node {
59-
id
60-
title
61-
categories
62-
}
63-
}
64-
}
65-
}
66-
`);
67-
68-
blogsFromMedium.data.allFeedMediumBlog.edges.forEach(edge => {
69-
const slug = edge.node.title
70-
.toLowerCase()
71-
.replace(/[^\w ]+/g, '')
72-
.replace(/ +/g, '-');
73-
const id = edge.node.id;
74-
75-
// If there are no categories it's a comment
76-
if (edge.node.categories) {
77-
createPage({
78-
path: 'post/' + slug,
79-
component: blogTemplate,
80-
context: {
81-
id,
82-
},
83-
});
84-
}
85-
});
8654
const allMarkdownArticles = await graphql(
8755
`
8856
{
@@ -102,21 +70,18 @@ exports.createPages = async ({ graphql, actions }) => {
10270
}
10371
`
10472
);
73+
allMarkdownArticles.data.allMarkdownRemark.edges.forEach(edge => {
74+
const slug = edge.node.frontmatter.slug;
75+
const id = edge.node.id;
10576

106-
if (allMarkdownArticles.data) {
107-
allMarkdownArticles.data.allMarkdownRemark.edges.forEach(edge => {
108-
const slug = edge.node.frontmatter.slug;
109-
const id = edge.node.id;
110-
111-
createPage({
112-
path: 'post/' + slug,
113-
component: blogTemplate,
114-
context: {
115-
id,
116-
},
117-
});
77+
createPage({
78+
path: 'post/' + slug,
79+
component: blogTemplate,
80+
context: {
81+
id,
82+
},
11883
});
119-
}
84+
});
12085

12186
const allDocs = await graphql(
12287
`
@@ -137,13 +102,11 @@ exports.createPages = async ({ graphql, actions }) => {
137102
}
138103
`
139104
);
140-
141105
if (allDocs.errors) {
142106
console.error(allDocs.errors);
143107

144108
throw Error(allDocs.errors);
145109
}
146-
147110
allDocs.data.allMarkdownRemark.edges.forEach(edge => {
148111
const slug = edge.node.fields.slug;
149112
const url = edge.node.fields.url;
@@ -189,7 +152,6 @@ exports.createPages = async ({ graphql, actions }) => {
189152
}
190153
`
191154
);
192-
193155
if (allJobs.data) {
194156
allJobs.data.allMarkdownRemark.edges.forEach(edge => {
195157
createPage({

packages/homepage/src/pages/blog.js

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import React from 'react';
2-
import { graphql, Link } from 'gatsby';
31
import { format } from 'date-fns';
4-
import TitleAndMetaTags from '../components/TitleAndMetaTags';
5-
import PageContainer from '../components/PageContainer';
2+
import { graphql, Link } from 'gatsby';
3+
import React from 'react';
64

5+
import PageContainer from '../components/PageContainer';
76
import {
8-
Title,
9-
PostDate,
10-
AuthorImage,
117
Author,
8+
AuthorImage,
9+
PostDate,
10+
Title,
1211
} from '../components/PostElements';
12+
import TitleAndMetaTags from '../components/TitleAndMetaTags';
1313

1414
import {
1515
Posts,
@@ -28,18 +28,20 @@ import { makeFeed } from '../utils/makePosts';
2828
// UNCOMMENT AT THE BOTTOM IF IT BREAKS
2929
// GATSBY DOES NOT LET YOU HAVE FIELDS THAT DON'T EXIST YET
3030

31-
const Info = ({ post, mobile, ...props }) => (
31+
const Info = ({ mobile, post: { creator, date, photo }, ...props }) => (
3232
<Aside mobile={mobile} {...props}>
33-
<PostDate>{format(post.date, 'MMM DD, YYYY')}</PostDate>
33+
<PostDate>{format(date, 'MMM DD, YYYY')}</PostDate>
34+
3435
<section>
35-
<AuthorImage src={post.photo} alt={post.creator} />
36-
<Author>{post.creator}</Author>
36+
<AuthorImage src={photo} alt={creator} />
37+
38+
<Author>{creator}</Author>
3739
</section>
3840
</Aside>
3941
);
4042

41-
const Blog = ({ data: { allFeedMediumBlog, allMarkdownRemark } }) => {
42-
const posts = makeFeed(allFeedMediumBlog, allMarkdownRemark);
43+
const Blog = ({ data: { allMarkdownRemark } }) => {
44+
const posts = makeFeed(allMarkdownRemark);
4345

4446
return (
4547
<Layout>
@@ -48,28 +50,33 @@ const Blog = ({ data: { allFeedMediumBlog, allMarkdownRemark } }) => {
4850
description="Here you can find articles written by the team and external contributors"
4951
title="Blog - CodeSandbox"
5052
/>
53+
5154
<Header>
5255
<PageTitle>Blog</PageTitle>
56+
5357
<PageSubtitle>
5458
Welcome to the CodeSandbox blog. Here you can find posts about new
5559
releases, tips and tricks and how we made CodeSandbox.
5660
</PageSubtitle>
5761
</Header>
62+
5863
{posts.map(post => (
5964
<Wrapper key={post.id}>
6065
<Info post={post} />
66+
6167
<Posts>
6268
{post.src && (
6369
<Link
6470
css={`
65-
text-decoration: none;
6671
display: contents;
72+
text-decoration: none;
6773
`}
6874
to={`post/${post.slug}`}
6975
>
70-
<Thumbnail src={post.src} width="340" alt={post.title} />
76+
<Thumbnail alt={post.title} src={post.src} width="340" />
7177
</Link>
7278
)}
79+
7380
<div>
7481
<Link
7582
css={`
@@ -79,8 +86,10 @@ const Blog = ({ data: { allFeedMediumBlog, allMarkdownRemark } }) => {
7986
>
8087
<Title>{post.title}</Title>
8188
</Link>
89+
8290
<Subtitle>{post.subtitle}</Subtitle>
8391
</div>
92+
8493
<Info post={post} mobile />
8594
</Posts>
8695
</Wrapper>
@@ -114,20 +123,6 @@ export const query = graphql`
114123
}
115124
}
116125
}
117-
allFeedMediumBlog {
118-
edges {
119-
node {
120-
id
121-
categories
122-
creator
123-
title
124-
isoDate
125-
content {
126-
encoded
127-
}
128-
}
129-
}
130-
}
131126
}
132127
`;
133128

packages/homepage/src/templates/post.js

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1+
import { format } from 'date-fns';
2+
import { graphql } from 'gatsby';
13
import React from 'react';
24

3-
import { graphql } from 'gatsby';
4-
import { format } from 'date-fns';
5-
import TitleAndMetaTags from '../components/TitleAndMetaTags';
65
import Layout from '../components/layout';
76
import PageContainer from '../components/PageContainer';
8-
import { mainStyle, Image } from './_post.elements';
9-
107
import {
8+
Author,
9+
AuthorImage,
1110
Container,
12-
Title,
1311
PostDate,
14-
AuthorImage,
15-
Author,
12+
Title,
1613
} from '../components/PostElements';
14+
import TitleAndMetaTags from '../components/TitleAndMetaTags';
1715
import { makePost } from '../utils/makePosts';
1816

19-
export default ({ data: { feedMediumBlog, markdownRemark } }) => {
17+
import { mainStyle, Image } from './_post.elements';
18+
19+
export default ({ data: { markdownRemark } }) => {
2020
const {
2121
creator,
2222
title,
@@ -25,7 +25,7 @@ export default ({ data: { feedMediumBlog, markdownRemark } }) => {
2525
photo,
2626
featuredImage,
2727
description,
28-
} = makePost(markdownRemark, feedMediumBlog);
28+
} = makePost(markdownRemark);
2929

3030
const featuredImageUrl = (featuredImage || '').includes('http')
3131
? featuredImage
@@ -34,31 +34,37 @@ export default ({ data: { feedMediumBlog, markdownRemark } }) => {
3434
<Layout>
3535
<Container style={{ overflowX: 'auto' }}>
3636
<TitleAndMetaTags
37-
title={`${title} - CodeSandbox Blog`}
38-
image={featuredImageUrl}
3937
description={description}
38+
image={featuredImageUrl}
39+
title={`${title} - CodeSandbox Blog`}
4040
/>
41+
4142
<PageContainer width={800}>
4243
<Title>{title}</Title>
44+
4345
<aside
4446
css={`
45-
display: flex;
4647
align-items: center;
48+
display: flex;
4749
`}
4850
>
4951
<div
5052
css={`
51-
display: flex;
5253
align-items: center;
54+
display: flex;
5355
flex: 1;
5456
`}
5557
>
5658
<AuthorImage src={photo} alt={creator} />
59+
5760
<Author>{creator}</Author>
5861
</div>
62+
5963
<PostDate>{format(date, 'MMM DD, YYYY')}</PostDate>
6064
</aside>
61-
{featuredImage ? <Image src={featuredImage} alt={title} /> : null}
65+
66+
{featuredImage ? <Image alt={title} src={featuredImage} /> : null}
67+
6268
<div
6369
css={mainStyle}
6470
dangerouslySetInnerHTML={{
@@ -73,18 +79,6 @@ export default ({ data: { feedMediumBlog, markdownRemark } }) => {
7379

7480
export const pageQuery = graphql`
7581
query Post($id: String) {
76-
feedMediumBlog(id: { eq: $id }) {
77-
id
78-
categories
79-
creator
80-
link
81-
title
82-
pubDate
83-
isoDate
84-
content {
85-
encoded
86-
}
87-
}
8882
markdownRemark(id: { eq: $id }) {
8983
html
9084
frontmatter {

0 commit comments

Comments
 (0)