1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
import GithubIcon from '@assets/images/social-media/github.svg';
import GitlabIcon from '@assets/images/social-media/gitlab.svg';
import { ProjectMeta } from '@ts/types/app';
import { settings } from '@utils/config';
import { getFormattedDate } from '@utils/helpers/format';
import { slugify } from '@utils/helpers/slugify';
import useGithubApi from '@utils/hooks/useGithubApi';
import Image from 'next/image';
import { useRouter } from 'next/router';
import { useIntl } from 'react-intl';
import styles from './ProjectSummary.module.scss';
const ProjectSummary = ({
id,
meta,
}: {
id: string;
title: string;
meta: ProjectMeta;
}) => {
const { hasCover, license, repos, technologies } = meta;
const intl = useIntl();
const router = useRouter();
const locale = router.locale ? router.locale : settings.locales.defaultLocale;
const { data } = useGithubApi(repos?.github ? repos.github : '');
return (
<div className={styles.wrapper}>
{hasCover && (
<div className={styles.cover}>
<Image
src={`/projects/${id}.jpg`}
alt={intl.formatMessage({
defaultMessage: '{title} preview',
description: 'ProjectSummary: cover alt text',
})}
layout="fill"
objectFit="contain"
/>
</div>
)}
<dl className={styles.info}>
{data && (
<div className={styles.info__item}>
<dt>
{intl.formatMessage({
defaultMessage: 'Created on:',
description: 'ProjectSummary: creation date label',
})}
</dt>
<dd>
<time dateTime={data.created_at}>
{getFormattedDate(data.created_at, locale)}
</time>
</dd>
</div>
)}
{data && (
<div className={styles.info__item}>
<dt>
{intl.formatMessage({
defaultMessage: 'Last updated on:',
description: 'ProjectSummary: update date label',
})}
</dt>
<dd>
<time dateTime={data.updated_at}>
{getFormattedDate(data.updated_at, locale)}
</time>
</dd>
</div>
)}
<div className={styles.info__item}>
<dt>
{intl.formatMessage({
defaultMessage: 'License:',
description: 'ProjectSummary: license label',
})}
</dt>
<dd>{license}</dd>
</div>
{technologies && (
<div className={styles.info__item}>
<dt>
{intl.formatMessage(
{
defaultMessage:
'{count, plural, =0 {Technologies:} one {Technology:} other {Technologies:}}',
description: 'ProjectSummary: technologies list label',
},
{ count: technologies.length }
)}
</dt>
{technologies.map((techno) => (
<dd
key={slugify(techno)}
className={`${styles.techno} ${styles['inline-data']}`}
>
{techno}
</dd>
))}
</div>
)}
{repos && (
<div className={styles.info__item}>
<dt>
{intl.formatMessage(
{
defaultMessage:
'{count, plural, =0 {Repositories:} one {Repository:} other {Repositories:}}',
description: 'ProjectSummary: repositories list label',
},
{ count: Object.keys(repos).length }
)}
</dt>
{repos.github && (
<dd className={styles['inline-data']}>
<a
href={`https://github.com/${repos.github}`}
className={styles.repo}
>
<GithubIcon />
<span className="screen-reader-text">Github</span>
</a>
</dd>
)}
{repos.gitlab && (
<dd className={styles['inline-data']}>
<a
href={`https://gitlab.com/${repos.gitlab}`}
className={styles.repo}
>
<GitlabIcon />
<span className="screen-reader-text">Gitlab</span>
</a>
</dd>
)}
</div>
)}
{data && repos && (
<div>
<dt>
{intl.formatMessage({
defaultMessage: 'Popularity:',
description: 'ProjectSummary: popularity label',
})}
</dt>
{repos.github && (
<dd>
⭐
<a href={`https://github.com/${repos.github}/stargazers`}>
{intl.formatMessage(
{
defaultMessage:
'{starsCount, plural, =0 {0 stars on Github} one {# star on Github} other {# stars on Github}}',
description: 'ProjectSummary: technologies list label',
},
{ starsCount: data.stargazers_count }
)}
</a>
</dd>
)}
</div>
)}
</dl>
</div>
);
};
export default ProjectSummary;
|