-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bce0b21
commit 4c2d115
Showing
4 changed files
with
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { VscGitCommit } from 'react-icons/vsc'; | ||
import { createStyles, makeStyles, Theme } from '@material-ui/core'; | ||
|
||
const useStyles = makeStyles((theme: Theme) => | ||
createStyles({ | ||
link: { | ||
textDecoration: 'none', | ||
color: theme.palette.text.primary, | ||
'&:hover': { | ||
textDecorationLine: 'underline', | ||
}, | ||
}, | ||
GitHubInfo: { | ||
lineHeight: '2rem', | ||
fontSize: '1.2rem', | ||
}, | ||
GitHubLinkTitle: { | ||
fontSize: '1.4rem', | ||
margin: 0, | ||
paddingTop: '1rem', | ||
}, | ||
icon: { | ||
fontSize: '2rem', | ||
marginRight: '1rem', | ||
verticalAlign: 'text-bottom', | ||
}, | ||
commits: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
margin: 0, | ||
}, | ||
commit: { | ||
marginRight: '2rem', | ||
}, | ||
}) | ||
); | ||
|
||
const SHORT_SHA_LENGTH = 7; | ||
|
||
const getCommitNumber = (url: string, length?: number) => | ||
url.replace(/.+\/(commit|commits)\/(\w{40}).*/, '$2').substr(0, length); | ||
|
||
type Props = { | ||
commitUrls: string[]; | ||
}; | ||
|
||
const Commits = ({ commitUrls }: Props) => { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<div className={classes.GitHubInfo}> | ||
<h2 className={classes.GitHubLinkTitle}> | ||
<VscGitCommit className={classes.icon}></VscGitCommit> | ||
{commitUrls.length === 1 ? 'Commit' : 'Commits'} | ||
</h2> | ||
<p className={classes.commits}> | ||
{commitUrls.map((url) => ( | ||
<p key={url} className={classes.commit}> | ||
<a | ||
href={`https://github.com${url}`} | ||
rel="bookmark" | ||
target="_blank" | ||
title={'Commit ' + getCommitNumber(url)} | ||
className={classes.link} | ||
> | ||
{getCommitNumber(url, SHORT_SHA_LENGTH)} | ||
</a> | ||
</p> | ||
))} | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Commits; |
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