-
Notifications
You must be signed in to change notification settings - Fork 785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(MediumPosts): automates pulling in posts from our Medium account #2562
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/gatsby-theme-carbon/components/MediumPosts/MediumPosts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from 'react'; | ||
import { useStaticQuery, graphql } from 'gatsby'; | ||
import PropTypes from 'prop-types'; | ||
import { Column, Row } from 'gatsby-theme-carbon/src/components/Grid'; | ||
import ArticleCard from 'gatsby-theme-carbon/src/components/ArticleCard'; | ||
import { image, cardContainer } from './MediumPosts.module.scss'; | ||
|
||
const MediumPosts = ({ | ||
postLimit = 3, | ||
cardProps, | ||
color = 'white', | ||
...rest | ||
}) => { | ||
const data = useStaticQuery(graphql` | ||
query { | ||
allMediumFeed(sort: { fields: date, order: DESC }, limit: 10) { | ||
edges { | ||
node { | ||
author | ||
date(formatString: "MMMM Do, YYYY") | ||
slug | ||
thumbnail | ||
title | ||
link | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
const allPosts = data.allMediumFeed.edges.map(({ node }) => node); | ||
|
||
return ( | ||
<Row {...rest}> | ||
{allPosts.slice(0, postLimit).map((latestPost, i) => ( | ||
<Column | ||
colSm={4} | ||
colMd={4} | ||
colLg={4} | ||
noGutterMdLeft | ||
key={i} | ||
className={cardContainer}> | ||
<ArticleCard | ||
title={latestPost.title} | ||
author={latestPost.author} | ||
href={latestPost.link} | ||
date={latestPost.date} | ||
color={color} | ||
{...cardProps}> | ||
<img | ||
alt={latestPost.title} | ||
src={latestPost.thumbnail} | ||
className={image} | ||
/> | ||
</ArticleCard> | ||
</Column> | ||
))} | ||
</Row> | ||
); | ||
}; | ||
|
||
MediumPosts.propTypes = { | ||
cardProps: PropTypes.object, | ||
postLimit: PropTypes.number, | ||
}; | ||
|
||
export default MediumPosts; |
57 changes: 57 additions & 0 deletions
57
src/gatsby-theme-carbon/components/MediumPosts/MediumPosts.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Fixes the gutter of the article cards on the homepage | ||
.card-container { | ||
padding-right: 0; | ||
padding-left: 0; | ||
@include carbon--breakpoint('md') { | ||
padding-right: 1rem; | ||
padding-left: 1rem; | ||
} | ||
} | ||
|
||
// Fixs the breaking type | ||
|
||
.card-container h4 { | ||
@include carbon--breakpoint('sm') { | ||
@include carbon--type-style('productive-heading-03'); | ||
} | ||
|
||
@include carbon--breakpoint('md') { | ||
font-size: 1rem; | ||
font-weight: 400; | ||
line-height: 1.2rem; | ||
letter-spacing: 0; | ||
} | ||
|
||
@include carbon--breakpoint('lg') { | ||
font-size: 0.75rem; | ||
font-weight: 400; | ||
line-height: 1rem; | ||
letter-spacing: 0; | ||
} | ||
@include carbon--breakpoint('xlg') { | ||
font-size: 1rem; | ||
font-weight: 400; | ||
line-height: 1.375rem; | ||
letter-spacing: 0; | ||
} | ||
} | ||
|
||
// Images pulled from the Medium RSS feed are different sizes and aspect ratios. This will make the cards different sizes. The class below fixes that issue. | ||
|
||
.image { | ||
object-fit: cover; | ||
width: 100%; | ||
|
||
@include carbon--breakpoint('sm') { | ||
height: 315px; | ||
} | ||
@include carbon--breakpoint('md') { | ||
height: 290px; | ||
} | ||
@include carbon--breakpoint('lg') { | ||
height: 165px; | ||
} | ||
@include carbon--breakpoint('xlg') { | ||
height: 215px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import MediumPosts from './MediumPosts'; | ||
|
||
export default MediumPosts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe here we add a conditional? if there isn't an img presented with the post, we add our own src for a "generic" img. I think it would be good to have a fallback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc: @thyhmdo do we have a generic carbon img we can use for blog posts that may not include an img already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked into it and unfortunately the API that it pulling the image source is pulling
https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eba9db004a3a
as opposed to null. I would need to refactor the MediumPosts component with some Regex logic to work around this. For now, maybe we just use whatever image Thy has and just make sure we have images in our blog posts from here on out.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and add it where? to the medium post itself? Definitely think we should try our best to add images to blog posts, but I don't think we should just bank on that. I'm ok with getting this PR in for now and we can open an issue in GTC for an enhancement to allow for a fallback img.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's just this one blog post without an image that's causing the kerfluffle. If Thy can whip one up for it, problem solved. We just need to make sure our Medium posts have images when they are published for future posts. But I also agree with you, drumming up an issue for GTC is the way to go.