-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MediumPosts): Component to automatically generate latest Medium …
…posts on build time. (#482) * v0.0.0 * v1.19.1 * new MediumPost component and all the supporting docs * removed version from package.json * added an anchorlink for Medium * v1.15.3 * v1.15.3 * v1.15.3 * v1.15.3 * v1.15.3 * images now use object-fit to maintain aspect ratio * fixed the height on xlg screens * fixed aspect ratio * fixed again
- Loading branch information
1 parent
485aa7f
commit 19b5e70
Showing
11 changed files
with
206 additions
and
3 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
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,27 @@ | ||
--- | ||
title: MediumPosts | ||
description: Guide for pulling Medium posts through their RSS feed using a Gatsby plugin. | ||
--- | ||
|
||
<PageDescription> | ||
|
||
Using a Gatsby plugin, this component automatically builds three `ArticleCards` populated with the most recent Medium posts at build time. | ||
|
||
</PageDescription> | ||
|
||
## Example | ||
|
||
<MediumPosts color="dark" posts={3} /> | ||
|
||
## Code | ||
|
||
```jsx path=components/MediumPosts/MediumPosts.js src=https://github.com/carbon-design-system/gatsby-theme-carbon/tree/master/packages/gatsby-theme-carbon/src/components/MediumPosts | ||
<MediumPosts color="dark" posts={3} /> | ||
``` | ||
|
||
## Props | ||
|
||
| property | propType | required | default | description | | ||
| -------- | -------- | -------- | ------- | --------------------------------------------------------------------------------------------- | | ||
| color | string | | `light` | Sets the card for the correct color theme, default is `light`, options are `light` and `dark` | | ||
| posts | number | | `3` | Sets the number of posts pulled from Medium, default is `3`, maximum is `10`. | |
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
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
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
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
69 changes: 69 additions & 0 deletions
69
packages/gatsby-theme-carbon/src/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,69 @@ | ||
import React from 'react'; | ||
import { useStaticQuery, graphql } from 'gatsby'; | ||
import PropTypes from 'prop-types'; | ||
import { Column, Row } from '../Grid'; | ||
import ArticleCard from '../ArticleCard'; | ||
|
||
const MediumPosts = ({ color, posts }) => { | ||
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); | ||
|
||
const defaultProps = { | ||
defaultPosts: 3, | ||
}; | ||
|
||
const latestPosts = allPosts.slice(0, posts || defaultProps.defaultPosts); | ||
|
||
return ( | ||
<> | ||
<Row> | ||
{latestPosts.map(latestPost => ( | ||
<Column | ||
colSm={4} | ||
colMd={4} | ||
colLg={4} | ||
noGutterMdLeft | ||
className="medium-posts-article-gutter medium-posts-type-size" | ||
> | ||
<ArticleCard | ||
title={latestPost.title} | ||
author={latestPost.author} | ||
href={latestPost.link} | ||
color={color} | ||
date={latestPost.date} | ||
> | ||
<img | ||
alt={latestPost.title} | ||
src={latestPost.thumbnail} | ||
className="medium-image-container" | ||
/> | ||
</ArticleCard> | ||
</Column> | ||
))} | ||
</Row> | ||
</> | ||
); | ||
}; | ||
|
||
MediumPosts.propTypes = { | ||
color: PropTypes.string, | ||
posts: PropTypes.number, | ||
}; | ||
|
||
export default MediumPosts; |
3 changes: 3 additions & 0 deletions
3
packages/gatsby-theme-carbon/src/components/MediumPosts/index.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,3 @@ | ||
import MediumPosts from './MediumPosts'; | ||
|
||
export default MediumPosts; |
57 changes: 57 additions & 0 deletions
57
packages/gatsby-theme-carbon/src/components/MediumPosts/medium-posts.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 | ||
.medium-posts-article-gutter { | ||
padding-right: 0; | ||
padding-left: 0; | ||
@include carbon--breakpoint('md') { | ||
padding-right: 1rem; | ||
padding-left: 1rem; | ||
} | ||
} | ||
|
||
// Fixs the breaking type | ||
|
||
.medium-posts-type-size 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. | ||
|
||
.medium-image-container { | ||
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
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
19b5e70
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.
Successfully deployed to following URLs: