diff --git a/angular-primeng-app/src/app/app.component.ts b/angular-primeng-app/src/app/app.component.ts index 1bf9402..e632623 100644 --- a/angular-primeng-app/src/app/app.component.ts +++ b/angular-primeng-app/src/app/app.component.ts @@ -1,5 +1,10 @@ -import { Component } from '@angular/core'; +import { Component, OnInit, OnDestroy, inject, Inject } from '@angular/core'; import { RouterOutlet } from '@angular/router'; +import { Subscription } from 'rxjs'; +import { BlogInfo } from './models/blog-info'; +import { BlogService } from './services/blog.service'; +import { ThemeService } from './services/theme.service'; +import { DOCUMENT } from '@angular/common'; @Component({ selector: 'app-root', @@ -8,6 +13,42 @@ import { RouterOutlet } from '@angular/router'; templateUrl: './app.component.html', styleUrl: './app.component.scss' }) -export class AppComponent { +export class AppComponent implements OnInit, OnDestroy { title = 'angular-primeng-app'; + blogURL!: string; + blogInfo!: BlogInfo; + siteFavicon: any; + themeService: ThemeService = inject(ThemeService); + blogService: BlogService = inject(BlogService); + private querySubscription?: Subscription; + + constructor(@Inject(DOCUMENT) private document: Document) {} + + ngOnInit(): void { + this.blogURL = this.blogService.getBlogURL(); + this.siteFavicon = this.document.querySelector('link[rel="icon"]') as HTMLLinkElement; + this.querySubscription = this.blogService + .getBlogInfo(this.blogURL) + .subscribe((data) => { + this.blogInfo = data; + if (this.blogInfo.isTeam && this.blogInfo.favicon) { + this.siteFavicon.href = this.blogInfo.favicon; + } else { + this.siteFavicon.href = "favicon.ico"; + } + if (!this.blogInfo.isTeam) { + this.blogService.getAuthorInfo(this.blogURL).subscribe((data) => { + if (data.profilePicture) { + this.siteFavicon.href = data.profilePicture; + } else { + this.siteFavicon.href = "favicon.ico"; + } + }); + } + }); + } + + ngOnDestroy(): void { + this.querySubscription?.unsubscribe(); + } } diff --git a/angular-primeng-app/src/app/app.routes.ts b/angular-primeng-app/src/app/app.routes.ts index ab0e116..0fc1c66 100644 --- a/angular-primeng-app/src/app/app.routes.ts +++ b/angular-primeng-app/src/app/app.routes.ts @@ -23,5 +23,9 @@ export const routes: Routes = [ { path: 'post/:slug', component: PostDetailsComponent + }, + { + path: '**', + redirectTo: '' } ];