feat: Set the browser title based on what section of the app you are on (#947)

* when reading a book, set the page title

* set page title on various sections of the app

* update page title service
This commit is contained in:
Ionuț Staicu
2025-10-31 10:31:30 -06:00
committed by GitHub
parent d542c87afb
commit db9bc40960
10 changed files with 77 additions and 5 deletions
@@ -0,0 +1,25 @@
import {inject, Injectable} from "@angular/core";
import {Title} from "@angular/platform-browser";
import {Book} from "../../features/book/model/book.model";
@Injectable({providedIn: 'root'})
export class PageTitleService {
private titleService = inject(Title)
private appName = 'BookLore'
setBookPageTitle(book: Book) {
const title = [
`${book.libraryName}/${book.metadata?.title || book.fileName}`,
book.metadata?.seriesName ? `(${book.metadata.seriesName} series)` : false,
book.metadata?.authors?.length ? `- by ${new Intl.ListFormat('en').format(book.metadata?.authors)}` : false,
`(${book.bookType})`
].filter(part => part);
this.setPageTitle(title.join(' '));
}
setPageTitle(pageTitle: string) {
this.titleService.setTitle([pageTitle, this.appName].filter(part => part).join(' - '));
}
}