Skip to content

fix: Show GitHub stars on social wrapper #3294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions src/app/common/social-wrapper/social-wrapper.component.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
<div class="social-wrapper">
<a href="https://twitter.com/nestframework"
title="Twitter account"
target="_blank">
<a
href="https://twitter.com/nestframework"
title="Twitter account"
target="_blank"
>
<i class="fa-brands fa-x-twitter"></i>
</a>
<a href="https://github.com/nestjs/nest"
title="Github repository"
target="_blank">
<a
href="https://github.com/nestjs/nest"
title="Github repository"
target="_blank"
>
<i class="fa-brands fa-github"></i>
<span class="github-stars">{{ githubStars }}</span>
</a>
<a href="https://stackoverflow.com/questions/tagged/nestjs"
title="Stackoverflow"
target="_blank">
<a
href="https://stackoverflow.com/questions/tagged/nestjs"
title="Stackoverflow"
target="_blank"
>
<i class="fa-brands fa-stack-overflow"></i>
</a>
<a
Expand All @@ -21,10 +28,12 @@
>
<i class="fa fa-globe"></i>
</a>
<a href="https://discord.gg/G7Qnnhy"
title="Discord"
target="_blank"
rel="nofollow">
<a
href="https://discord.gg/G7Qnnhy"
title="Discord"
target="_blank"
rel="nofollow"
>
<i class="fa-brands fa-discord"></i>
</a>
</div>
6 changes: 6 additions & 0 deletions src/app/common/social-wrapper/social-wrapper.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@
display: none;
}
}

.github-stars{
padding: 0px 5px;
font-size: 15px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
38 changes: 35 additions & 3 deletions src/app/common/social-wrapper/social-wrapper.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
import { Component } from '@angular/core';
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
selector: 'app-social-wrapper',
templateUrl: './social-wrapper.component.html',
styleUrls: ['./social-wrapper.component.scss']
styleUrls: ['./social-wrapper.component.scss'],
})
export class SocialWrapperComponent {}
export class SocialWrapperComponent implements OnInit {
githubStars: string = '';

constructor(private http: HttpClient, private cdr: ChangeDetectorRef) {}

ngOnInit(): void {
const owner = 'nestjs';
const repo = 'nest';
const apiUrl = `https://api.github.com/repos/${owner}/${repo}`;

this.http.get<any>(apiUrl).subscribe({
next: (data) => {
const stars = data.stargazers_count;
this.githubStars = this.formatStars(stars);
this.cdr.detectChanges();
},
error: (err) => {
console.error('GitHub API error:', err);
},
});
}

private formatStars(count: number): string {
if (count >= 1_000_000) {
return (count / 1_000_000).toFixed(1).replace(/\.0$/, '') + 'M';
} else if (count >= 1_000) {
return (count / 1_000).toFixed(1).replace(/\.0$/, '') + 'k';
} else {
return count.toString();
}
}
}