]>
Commit | Line | Data |
---|---|---|
0f01a8ba C |
1 | import { Injectable } from '@angular/core' |
2 | import { Meta, Title } from '@angular/platform-browser' | |
3 | import { HTMLServerConfig } from '@shared/models/server' | |
4 | import { ServerService } from '../server' | |
5 | ||
6 | export interface MetaSettings { | |
7 | title?: string | |
8 | } | |
9 | ||
10 | @Injectable() | |
11 | export class MetaService { | |
12 | private config: HTMLServerConfig | |
13 | ||
14 | constructor ( | |
15 | private titleService: Title, | |
16 | private meta: Meta, | |
17 | private server: ServerService | |
18 | ) { | |
19 | this.config = this.server.getTmpConfig() | |
20 | this.server.getConfig() | |
21 | .subscribe(config => this.config = config) | |
22 | } | |
23 | ||
24 | setTitle (subTitle?: string) { | |
25 | let title = '' | |
26 | if (subTitle) title += `${subTitle} - ` | |
27 | ||
28 | title += this.config.instance.name | |
29 | ||
30 | this.titleService.setTitle(title) | |
31 | } | |
32 | ||
33 | setTag (name: string, value: string) { | |
34 | this.meta.addTag({ name, content: value }) | |
35 | } | |
36 | ||
37 | update (meta: MetaSettings) { | |
38 | this.setTitle(meta.title) | |
39 | } | |
40 | } |