mempool/frontend/src/app/services/seo.service.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-03-24 00:52:08 +07:00
import { Injectable } from '@angular/core';
import { Title, Meta } from '@angular/platform-browser';
import { StateService } from './state.service';
2020-03-24 00:52:08 +07:00
@Injectable({
providedIn: 'root'
})
export class SeoService {
network = '';
2020-03-24 00:52:08 +07:00
constructor(
private titleService: Title,
private metaService: Meta,
private stateService: StateService,
) {
this.stateService.networkChanged$.subscribe((network) => this.network = network);
}
2020-03-24 00:52:08 +07:00
2020-08-12 14:04:04 +07:00
setTitle(newTitle: string): void {
this.titleService.setTitle(newTitle + ' - ' + this.getTitle());
this.metaService.updateTag({ property: 'og:title', content: newTitle});
2020-03-24 00:52:08 +07:00
}
2020-08-12 14:04:04 +07:00
resetTitle(): void {
this.titleService.setTitle(this.getTitle());
this.metaService.updateTag({ property: 'og:title', content: this.getTitle()});
2020-08-12 14:04:04 +07:00
}
getTitle(): string {
if (this.network === 'liquid')
return 'mempool - Liquid Network';
if (this.network === 'bisq')
return 'mempool - Bisq Markets';
2020-08-12 14:04:04 +07:00
return 'mempool - ' + (this.network ? this.ucfirst(this.network) : 'Bitcoin') + ' Explorer';
}
ucfirst(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
2020-03-24 00:52:08 +07:00
}
}