forked from carbon-design-system/carbon-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MediumPosts): automates pulling in posts from our Medium account (…
…carbon-design-system#2562) * feat(MediumPosts): ta da * feat(MediumPosts): added to the latest news section * feat(MediumPosts): shadow'd component to fix colors
- Loading branch information
1 parent
8257a57
commit 2f5fc78
Showing
6 changed files
with
130 additions
and
359 deletions.
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.