Skip to content
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 3 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = {
baseUrl: 'https://github.com/carbon-design-system/carbon-website',
subDirectory: '',
},
mediumAccount: 'carbondesign',
},
},
{
Expand Down
67 changes: 67 additions & 0 deletions src/gatsby-theme-carbon/components/MediumPosts/MediumPosts.js
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}
/>
Comment on lines +50 to +54
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, maybe we just use whatever image Thy has

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.

Copy link
Member Author

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.

</ArticleCard>
</Column>
))}
</Row>
);
};

MediumPosts.propTypes = {
cardProps: PropTypes.object,
postLimit: PropTypes.number,
};

export default MediumPosts;
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;
}
}
3 changes: 3 additions & 0 deletions src/gatsby-theme-carbon/components/MediumPosts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import MediumPosts from './MediumPosts';

export default MediumPosts;
45 changes: 1 addition & 44 deletions src/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -126,47 +126,4 @@ building websites and user interfaces.

### Latest news and articles

<Row>
<Column colLg={4} colMd={4} noGutterMdLeft>

<ArticleCard
color="dark"
title="Carbon v11 Beta 1"
author="Josh Black"
date="August 6, 2021"
href="https://medium.com/carbondesign/carbon-v11-beta-1-33488b0280f0"
>

![Carbon v11 Beta 1](./homepage/images/carbon_2021-august-update.png)

</ArticleCard>
</Column>
<Column colLg={4} colMd={4} noGutterMdLeft>

<ArticleCard
color="dark"
title="Carbon’s 2021 release: April update"
author="Josh Black"
date="April 22, 2021"
href="https://medium.com/carbondesign/carbons-2021-release-april-update-9d23242b3dea"
>

![Carbon's 2021 release: April update](./homepage/images/carbon_2021-april-update.png)

</ArticleCard>
</Column>
<Column colLg={4} colMd={4} noGutterMdLeft>
<ArticleCard
color="dark"
title="The new Gatsby theme Sketch kit has arrived!"
author="Diana Stanciulescu"
date="April 1, 2021"
href="./designing/design-resources/#gatsby-theme-sketch-kit"
>

![Gatsby theme announcement](./homepage/images/gatsby_announcement.png)

</ArticleCard>
</Column>

</Row>
<MediumPosts postLimit={3} color="dark" />
Loading