diff --git a/src/app/common/social-wrapper/social-wrapper.component.html b/src/app/common/social-wrapper/social-wrapper.component.html index f4191b3d8f..42e86164b1 100644 --- a/src/app/common/social-wrapper/social-wrapper.component.html +++ b/src/app/common/social-wrapper/social-wrapper.component.html @@ -1,17 +1,24 @@
- + - + + {{ githubStars }} - + - +
diff --git a/src/app/common/social-wrapper/social-wrapper.component.scss b/src/app/common/social-wrapper/social-wrapper.component.scss index 8755dccb93..89c8f58dbd 100644 --- a/src/app/common/social-wrapper/social-wrapper.component.scss +++ b/src/app/common/social-wrapper/social-wrapper.component.scss @@ -54,3 +54,9 @@ display: none; } } + +.github-stars{ + padding: 0px 5px; + font-size: 15px; + font-family: Verdana, Geneva, Tahoma, sans-serif; +} \ No newline at end of file diff --git a/src/app/common/social-wrapper/social-wrapper.component.ts b/src/app/common/social-wrapper/social-wrapper.component.ts index 9d7c3c1a08..c30735cb21 100644 --- a/src/app/common/social-wrapper/social-wrapper.component.ts +++ b/src/app/common/social-wrapper/social-wrapper.component.ts @@ -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(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(); + } + } +}