diff --git a/src/app/components/repos/repos.component.html b/src/app/components/repos/repos.component.html index 72476fa..c234edd 100644 --- a/src/app/components/repos/repos.component.html +++ b/src/app/components/repos/repos.component.html @@ -1,11 +1,12 @@
- +
@for (rep of repo; let first = $first; track $index;) {
+
diff --git a/src/app/components/repos/repos.component.ts b/src/app/components/repos/repos.component.ts index bbca4ad..1bba1c7 100644 --- a/src/app/components/repos/repos.component.ts +++ b/src/app/components/repos/repos.component.ts @@ -1,8 +1,9 @@ +import { NgClass, NgIf } from '@angular/common'; import { Component, OnInit, inject } from '@angular/core'; import { DataViewModule } from 'primeng/dataview'; import { TagModule } from 'primeng/tag'; import { GithubService } from '../../services/github.service'; -import { NgClass, NgIf } from '@angular/common'; + @Component({ selector: 'app-repos', standalone: true, @@ -11,17 +12,24 @@ import { NgClass, NgIf } from '@angular/common'; styleUrl: './repos.component.scss', providers: [GithubService] }) + export class ReposComponent implements OnInit { private gitService = inject(GithubService); - + skeleton = { + card: false, + card_img: false + }; repos: any[] = []; ngOnInit(): void { - this.gitService.getAll('tauisilva').subscribe((p) => { - if (p) { - console.log(p[0]) - this.repos = p; + this.gitService.getAll('tauisilva').subscribe((repos) => { + if (repos) { + this.repos = repos; + repos.forEach(async (r: any) => { + const img = await this.gitService.getImg(r?.html_url).toPromise(); + r.img = img; + }); } }) } diff --git a/src/app/services/github.service.ts b/src/app/services/github.service.ts index 74d47ba..c16b461 100644 --- a/src/app/services/github.service.ts +++ b/src/app/services/github.service.ts @@ -1,5 +1,6 @@ import { HttpClient } from '@angular/common/http'; import { Injectable, inject } from '@angular/core'; +import { Observable, map } from 'rxjs'; import { environment } from '../../env/env'; @Injectable({ @@ -15,4 +16,19 @@ export class GithubService { return this.http.get(`${this.api}/users/${user}/repos`); } + getImg(url: string): Observable { + return this.http.get(url, { responseType: 'text' }) + .pipe(map((html: string) => this.extractImage(html))); + } + + private extractImage(html: string): string | null { + const parser = new DOMParser(); + const doc = parser.parseFromString(html, 'text/html'); + + const metaTags = doc.querySelectorAll('meta[property="og:image"], meta[property="twitter:image"]'); + const firstTag = metaTags[0] as HTMLMetaElement | undefined; + + return firstTag ? firstTag.content : null; + } + } diff --git a/src/app/services/theme.service.ts b/src/app/services/theme.service.ts index 9f04994..af56e56 100644 --- a/src/app/services/theme.service.ts +++ b/src/app/services/theme.service.ts @@ -9,7 +9,6 @@ export class ThemeService { getTheme() { const theme = sessionStorage.getItem('theme'); if (theme) { - console.log(theme) this.setTheme(theme); } } @@ -33,4 +32,4 @@ export class ThemeService { sessionStorage.setItem('theme', isDark ? 'dark' : 'light'); this.setTheme(isDark ? 'dark' : 'light'); } -} +} \ No newline at end of file