Skip to content

Commit aaad8c3

Browse files
committed
Contributor added
1 parent 9bfaf31 commit aaad8c3

4 files changed

Lines changed: 74 additions & 5 deletions

File tree

src/App.css

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,42 @@ pre.code {
162162
overflow-y: hidden;
163163
}
164164

165+
.contributor {
166+
list-style: none;
167+
margin-bottom: 15px;
168+
}
169+
170+
.contributor p {
171+
margin-bottom: 10px;
172+
font-weight: 900;
173+
}
174+
175+
.contributor li {
176+
display: inline-block;
177+
position: relative;
178+
margin: 0 5px;
179+
}
180+
181+
.contributor-profile span {
182+
position: absolute;
183+
bottom: 5px;
184+
right: -2px;
185+
font-weight: bold;
186+
background-color: #4CAF50;
187+
color: #fff;
188+
font-size: 11px;
189+
width: 15px;
190+
height: 15px;
191+
line-height: 15px;
192+
border-radius: 40px;
193+
}
194+
195+
.contributor-profile img {
196+
width: 40px;
197+
border-radius: 40px;
198+
border: 3px solid #FFC107;
199+
}
200+
165201
.single-content {
166202
display: flex;
167203
flex-wrap: wrap;
@@ -424,4 +460,4 @@ footer ul li a {
424460
.footer-area {
425461
visibility: hidden !important;
426462
}
427-
}
463+
}

src/components/Content.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import HeaderContent from './HeaderContent';
88
import Page404 from './404';
99
import Footer from './Footer';
1010

11+
import contributorMap from '../utils/contributorMap';
12+
1113
class Content extends Component {
1214
state = {
1315
data: '',
16+
contributor: '',
1417
redirect: false
1518
}
1619

@@ -27,15 +30,17 @@ class Content extends Component {
2730
getData = async(id) => {
2831
try {
2932
const { data } = await axios(`https://raw.githubusercontent.com/devsonket/devsonket.github.io/develop/data/${id}.json`);
30-
this.setState({data});
33+
let { data: contributor } = await axios(`https://api.github.com/repos/devsonket/devsonket.github.io/commits?path=data/${id}.json`);
34+
contributor = contributorMap(contributor);
35+
this.setState({data, contributor});
3136
this.setTitle();
3237
} catch(e) {
3338
this.setState({redirect: true})
3439
}
3540
}
3641

3742
render() {
38-
const { data, redirect } = this.state;
43+
const { data, contributor, redirect } = this.state;
3944
const { match: { url } } = this.props;
4045

4146
if(redirect && url !== '/404') {
@@ -54,7 +59,7 @@ class Content extends Component {
5459

5560
return (
5661
<React.Fragment>
57-
<HeaderContent title={data.title} description={data.description} />
62+
<HeaderContent title={data.title} description={data.description} contributor={contributor} />
5863
<Container>
5964
<div className="single-content">
6065
{data.contents.map(({title, items, code: onlyCode}, index) => (

src/components/HeaderContent.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import SocialShare from './SocialShare';
55

66
export default class HeaderContent extends PureComponent {
77
render() {
8-
const {title, description} = this.props;
8+
const {title, description, contributor} = this.props;
99

1010
return (
1111
<header className="header-area">
@@ -14,6 +14,17 @@ export default class HeaderContent extends PureComponent {
1414
<div className="intro">
1515
<h1>{title}</h1>
1616
<p>{description}</p>
17+
<ul className="contributor">
18+
<p>কন্ট্রিবিউটর</p>
19+
{Object.keys(contributor).map(oneContributor => (
20+
<li key={oneContributor}>
21+
<div className="contributor-profile">
22+
<a rel="noopener noreferrer" target="_blank" href={contributor[oneContributor].html_url}><img alt={contributor[oneContributor].login} src={contributor[oneContributor].avatar_url} /></a>
23+
<span>{contributor[oneContributor].count}</span>
24+
</div>
25+
</li>
26+
))}
27+
</ul>
1728
<div className="print no-print">
1829
<button className="btn btn-print" onClick={() => window.print()}>প্রিন্ট করুন</button>
1930
</div>

src/utils/contributorMap.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default data => {
2+
const charMap = {};
3+
data.forEach(oneData => {
4+
const { login } = oneData.author;
5+
if(!charMap[login]) {
6+
charMap[login] = {
7+
count: 1,
8+
login: oneData.author.login,
9+
avatar_url: oneData.author.avatar_url,
10+
html_url: oneData.author.html_url
11+
}
12+
} else {
13+
charMap[login].count++;
14+
}
15+
});
16+
return charMap;
17+
}

0 commit comments

Comments
 (0)