added page title service for displaying page title

This commit is contained in:
2026-11-12 22:25:42 +01:00
parent e984372259
commit 8b374681c2
@@ -0,0 +1,71 @@
import { Injectable, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { NavigationEnd, Router } from '@angular/router';
import { filter } from 'rxjs';
const APP_NAME = 'AIIS';
const TITLES: ReadonlyArray<{ prefix: string; title: string }> = [
{ prefix: '/person/', title: 'Person' },
{ prefix: '/persons', title: 'Personen' },
{ prefix: '/publication/', title: 'Publikation' },
{ prefix: '/publications', title: 'Publikationen' },
{ prefix: '/patent/', title: 'Patent' },
{ prefix: '/patents', title: 'Patente' },
{ prefix: '/institution/', title: 'Institution' },
{ prefix: '/institutions', title: 'Institutionen' },
{ prefix: '/topic/', title: 'Thema' },
{ prefix: '/topics', title: 'Themen' },
{ prefix: '/news/', title: 'Nachricht' },
{ prefix: '/news', title: 'Nachrichten' },
{ prefix: '/projects/', title: 'Projekt' },
{ prefix: '/projects', title: 'Projekte' },
{ prefix: '/founders/', title: 'Multiplikator' },
{ prefix: '/founders', title: 'Gründungspotenzial' },
{ prefix: '/multipliers', title: 'Multiplikatoren' },
{ prefix: '/compare', title: 'Autorenvergleich' },
{ prefix: '/bookmarks', title: 'Bookmarks' },
{ prefix: '/keywords/', title: 'Keywords' },
{ prefix: '/keywords', title: 'Keywords' },
{ prefix: '/hierarchy', title: 'Hierarchie' },
{ prefix: '/account', title: 'Mein Konto' },
{ prefix: '/accounts', title: 'Accounts' },
{ prefix: '/organizations', title: 'Organisationen' },
{ prefix: '/jobs', title: 'Jobs' },
{ prefix: '/dashboard', title: 'Dashboard' },
{ prefix: '/login', title: 'Anmelden' },
{ prefix: '/forgot-password', title: 'Passwort vergessen' },
{ prefix: '/reset-password', title: 'Passwort zurücksetzen' },
{ prefix: '/error', title: 'Fehler' },
{ prefix: '/icons', title: 'Icons' },
];
@Injectable({ providedIn: 'root' })
export class PageTitleService {
private readonly router = inject(Router);
constructor() {
this.router.events
.pipe(
filter(
(event): event is NavigationEnd => event instanceof NavigationEnd,
),
takeUntilDestroyed(),
)
.subscribe((event) => this.update(event.urlAfterRedirects));
this.update(this.router.url);
}
private update(url: string): void {
document.title = `${this.titleFor(url)} · ${APP_NAME}`;
}
private titleFor(url: string): string {
const path = url.split('?')[0].split('#')[0] || '/';
if (path === '/' || path === '') return 'Start';
const match = TITLES.find(({ prefix }) => path.startsWith(prefix));
return match?.title ?? 'Übersicht';
}
}