Skip to content

Commit d96f728

Browse files
committed
feat: add number of answers and people ansering
1 parent e42a40e commit d96f728

File tree

14 files changed

+139
-23
lines changed

14 files changed

+139
-23
lines changed

docs/astro.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export default defineConfig({
9393
TableOfContents: './src/components/TableOfContents.astro',
9494
PageTitle: './src/components/PageTitle.astro',
9595
MobileMenuFooter: './src/components/MobileMenuFooter.astro',
96+
SiteTitle: './src/components/SiteTitle.astro',
9697
},
9798
defaultLocale: 'root',
9899
locales,

docs/src/components/ActionButtonFooter.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ const { data } = await getEntry('i18n', lang);
1111
<div class="action-footer">
1212
<a class="action-button" href="/subscription">
1313
<div>{data['buttons.email']}</div>
14-
<Icon name="email" size="1rem" />
14+
<Icon name="email" />
1515
</a>
1616

1717
<a class="action-button" href="https://github.com/tomalaforge/angular-challenges">
1818
<div>{data['buttons.star']}</div>
19-
<Icon name="github" size="1rem" />
19+
<Icon name="github" />
2020
</a>
2121

2222
<a class="action-button button-sponsor" href="https://github.com/sponsors/tomalaforge">
2323
<div>{data['buttons.sponsor']}</div>
24-
<MyIcon name="heart" size="1rem" color="white" />
24+
<MyIcon name="heart" fill="none" stroke="currentColor" color="white" />
2525
</a>
2626
</div>
2727

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
const { challengeNumber } = Astro.props;
3+
const response = await fetch(`https://api.github.com/search/issues?q=repo:tomalaforge/angular-challenges+is:pr+label:%22${challengeNumber}%22+label:%22answer%22&per_page=1`);
4+
const { total_count } = await response.json();
5+
---
6+
7+
<div class="answer-text">Answered by {total_count} people</div>
8+
9+
<style>
10+
.answer-text {
11+
font-size: var(--sl-text-xs);
12+
color: var(--sl-color-gray-3);
13+
width: max-content;
14+
}
15+
</style>

docs/src/components/Author.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ const { name, twitter, linkedin, github, data } = Astro.props;
3131
display: flex;
3232
gap: 0.5rem;
3333
align-items: center;
34-
margin-top: -1rem;
3534
font-size: var(--sl-text-xs);
3635
color: var(--sl-color-gray-3);
36+
width: max-content;
3737
}
3838

3939
.icon {

docs/src/components/ChallengeFooter.astro

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ const { data } = await getEntry('i18n', lang);
1010
const authorLink = `https://github.com/tomalaforge/angular-challenges/pulls?q=label%3A${challengeNumber}+label%3A"answer+author"`;
1111
const communityLink = `https://github.com/tomalaforge/angular-challenges/pulls?q=label%3A${challengeNumber}+label%3Aanswer+sort%3Areactions-%2B1-desc`;
1212
const npxCommand = `npx nx serve ${command}`;
13+
14+
const response = await fetch(`https://api.github.com/search/issues?q=repo:tomalaforge/angular-challenges+is:pr+label:%22${challengeNumber}%22+label:%22answer%22`);
15+
const { total_count, items } = await response.json();
16+
17+
let count = 1;
18+
while(total_count > count*30) {
19+
const response = await fetch(`https://api.github.com/search/issues?q=repo:tomalaforge/angular-challenges+is:pr+label:%22${challengeNumber}%22+label:%22answer%22&page=${count}`);
20+
const { items: new_items } = await response.json();
21+
if(new_items && new_items.length === 0) break;
22+
items.push(...new_items);
23+
count++;
24+
}
25+
1326
---
1427

1528
<div class="separator"></div>
@@ -49,7 +62,7 @@ const npxCommand = `npx nx serve ${command}`;
4962
<div class="article-footer">
5063
<a
5164
href={communityLink}>
52-
{data['challenge.footer.communityAnswers']}*
65+
{total_count} {data['challenge.footer.communityAnswers']}*
5366
</a>
5467
<a
5568
href={authorLink}>
@@ -70,6 +83,20 @@ const npxCommand = `npx nx serve ${command}`;
7083
<VideoButton {...videoLink} {...Astro.props} />}
7184
</div>
7285

86+
<div class="solution-container">
87+
<div>Answered by</div>
88+
{(items ?? []).map((item) => (
89+
<img
90+
loading="lazy"
91+
src={item.user.avatar_url}
92+
width="30"
93+
height="30"
94+
alt=""
95+
class="avatar"
96+
/>
97+
))}
98+
</div>
99+
73100
<div class="footer-note">
74101
* {data['challenge.footer.upvoteAnswer']}
75102
</div>
@@ -93,5 +120,17 @@ const npxCommand = `npx nx serve ${command}`;
93120
gap: 0.25rem;
94121
margin-top: 3rem;
95122
}
123+
124+
125+
.solution-container {
126+
margin-top: 3rem;
127+
display: flex;
128+
flex-wrap: wrap;
129+
gap: 0.5rem;
130+
131+
img {
132+
border-radius: 50%;
133+
}
134+
}
96135
</style>
97136

docs/src/components/Content.astro

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,40 @@ import Author from './Author.astro';
66
import ChallengeFooter from './ChallengeFooter.astro';
77
import CommentSection from './CommentSection.astro';
88
import ContributorsFooter from './ContributorsFooter.astro';
9+
import AnswerNumber from './AnswerNumber.astro';
910
1011
const { lang } = Astro.props;
1112
const { data } = await getEntry('i18n', lang);
1213
const { challengeNumber } = Astro.props.entry.data;
1314
const author = Astro.props.entry.data.author ? await getEntry(Astro.props.entry.data.author) : null;
1415
const renderCommentSection = !Astro.props.entry.data.noCommentSection;
16+
1517
---
1618

17-
{ challengeNumber && author &&
18-
<Author {...author.data} {data} /> }
19+
{ challengeNumber ? <div class="header-container">
20+
{ author ? <Author {...author.data} {data} /> : null}
21+
<AnswerNumber {challengeNumber}/>
22+
</div> :null}
1923

2024
<Default {...Astro.props}>
2125
<slot />
2226
</Default>
2327

24-
{challengeNumber &&
25-
<ChallengeFooter {...Astro.props} />}
28+
{challengeNumber ?
29+
<ChallengeFooter {...Astro.props} /> : null}
2630

2731
{ renderCommentSection &&
2832
<CommentSection {...Astro.props} /> }
2933

3034
<ContributorsFooter {...Astro.props} />
3135

3236
<style>
33-
.author {
37+
.header-container {
38+
display: flex;
39+
justify-content: space-between;
40+
align-items: center;
41+
flex-wrap: wrap;
3442
margin-top: -1rem;
35-
font-size: var(--sl-text-xs);
36-
color: var(--sl-color-gray-3);
43+
3744
}
3845
</style>

docs/src/components/MyIcon.astro

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ interface Props {
99
class?: string;
1010
}
1111
12-
const { name, label, size = '1em', color } = Astro.props;
12+
const { name, label, size = '1em', color, fill="currentColor", stroke="none", viewBox="0 0 24 24" } = Astro.props;
1313
const a11yAttrs = label ? ({ 'aria-label': label } as const) : ({ 'aria-hidden': 'true' } as const);
1414
---
1515

16-
<svg height="1em" viewBox="0 0 512 512"
16+
<svg height="1em" width="1em" {viewBox}
1717
{...a11yAttrs}
1818
class={Astro.props.class}
19-
fill="currentColor"
19+
{fill}
20+
{stroke}
2021
set:html={Icons[name]}
2122
/>
2223

@@ -27,5 +28,6 @@ const a11yAttrs = label ? ({ 'aria-label': label } as const) : ({ 'aria-hidden':
2728
font-size: var(--sl-icon-size, 1em);
2829
width: 1em;
2930
height: 1em;
31+
stroke-width: 2;
3032
}
3133
</style>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
import { getEntry } from 'astro:content';
3+
import type { Props } from '@astrojs/starlight/props';
4+
import Default from '@astrojs/starlight/components/SiteTitle.astro';
5+
import MyIcon from './MyIcon.astro';
6+
const { challengeNumber } = Astro.props.entry.data;
7+
const { lang } = Astro.props;
8+
const { data } = await getEntry('i18n', lang);
9+
10+
const response = await fetch(`https://api.github.com/repos/tomalaforge/angular-challenges`);
11+
const { stargazers_count, forks } = await response.json();
12+
13+
14+
15+
16+
---
17+
18+
<Default {...Astro.props}>
19+
<slot />
20+
</Default>
21+
22+
<div class="github">
23+
<a class="category" href="https://github.com/tomalaforge/angular-challenges">
24+
<MyIcon name="star" />
25+
<div>{stargazers_count}</div>
26+
</a>
27+
28+
<div class="category fork">
29+
<MyIcon name="fork" viewBox="0 0 16 16" />
30+
<div>{forks}</div>
31+
</div>
32+
</div>
33+
34+
<style>
35+
.github {
36+
display: flex;
37+
flex-direction: column;
38+
align-items: flex-start;
39+
margin-left: var(--sl-nav-gap)
40+
}
41+
42+
.category {
43+
display: flex;
44+
align-items: center;
45+
font-size: 12px;
46+
gap: 0.25rem;
47+
}
48+
49+
.fork {
50+
//margin-top: -5px;
51+
}
52+
</style>

docs/src/components/icons.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const Icons = {
22
heart:
3-
'<path d="M225.8 468.2l-2.5-2.3L48.1 303.2C17.4 274.7 0 234.7 0 192.8v-3.3c0-70.4 50-130.8 119.2-144C158.6 37.9 198.9 47 231 69.6c9 6.4 17.4 13.8 25 22.3c4.2-4.8 8.7-9.2 13.5-13.3c3.7-3.2 7.5-6.2 11.5-9c0 0 0 0 0 0C313.1 47 353.4 37.9 392.8 45.4C462 58.6 512 119.1 512 189.5v3.3c0 41.9-17.4 81.9-48.1 110.4L288.7 465.9l-2.5 2.3c-8.2 7.6-19 11.9-30.2 11.9s-22-4.2-30.2-11.9zM239.1 145c-.4-.3-.7-.7-1-1.1l-17.8-20c0 0-.1-.1-.1-.1c0 0 0 0 0 0c-23.1-25.9-58-37.7-92-31.2C81.6 101.5 48 142.1 48 189.5v3.3c0 28.5 11.9 55.8 32.8 75.2L256 430.7 431.2 268c20.9-19.4 32.8-46.7 32.8-75.2v-3.3c0-47.3-33.6-88-80.1-96.9c-34-6.5-69 5.4-92 31.2c0 0 0 0-.1 .1s0 0-.1 .1l-17.8 20c-.3 .4-.7 .7-1 1.1c-4.5 4.5-10.6 7-16.9 7s-12.4-2.5-16.9-7z"/>',
4-
fillHeart:
5-
'<path d="M47.6 300.4L228.3 469.1c7.5 7 17.4 10.9 27.7 10.9s20.2-3.9 27.7-10.9L464.4 300.4c30.4-28.3 47.6-68 47.6-109.5v-5.8c0-69.9-50.5-129.5-119.4-141C347 36.5 300.6 51.4 268 84L256 96 244 84c-32.6-32.6-79-47.5-124.6-39.9C50.5 55.6 0 115.2 0 185.1v5.8c0 41.5 17.2 81.2 47.6 109.5z"/>',
3+
'<path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"></path>',
4+
star: '<path d="M22 9.67a1 1 0 0 0-.86-.67l-5.69-.83L12.9 3a1 1 0 0 0-1.8 0L8.55 8.16 2.86 9a1 1 0 0 0-.81.68 1 1 0 0 0 .25 1l4.13 4-1 5.68a1 1 0 0 0 1.45 1.07L12 18.76l5.1 2.68c.14.08.3.12.46.12a1 1 0 0 0 .99-1.19l-1-5.68 4.13-4A1 1 0 0 0 22 9.67Zm-6.15 4a1 1 0 0 0-.29.89l.72 4.19-3.76-2a1 1 0 0 0-.94 0l-3.76 2 .72-4.19a1 1 0 0 0-.29-.89l-3-3 4.21-.61a1 1 0 0 0 .76-.55L12 5.7l1.88 3.82a1 1 0 0 0 .76.55l4.21.61-3 2.99Z"/>',
5+
fork: '<path d="M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"/>',
66
};

docs/src/content/docs/es/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import SubscriptionForm from '../../../components/SubscriptionForm.astro';
7070

7171
<div class="article-footer">
7272
<a href="https://github.com/sponsors/tomalaforge" alt="Sponsor link">
73-
<MyIcon name="fillHeart" size="1.2rem" color="white" />
73+
<MyIcon name="heart" size="1.2rem" color="white" />
7474
Patrocina el Proyecto
7575
</a>
7676
</div>

0 commit comments

Comments
 (0)