Chocobozzz/PeerTube

View on GitHub
client/src/app/core/routing/meta.service.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { Injectable } from '@angular/core'
import { Meta, Title } from '@angular/platform-browser'
import { HTMLServerConfig } from '@peertube/peertube-models'
import { ServerService } from '../server'

export interface MetaSettings {
  title?: string
}

@Injectable()
export class MetaService {
  private config: HTMLServerConfig

  constructor (
    private titleService: Title,
    private meta: Meta,
    private server: ServerService
  ) {
    this.config = this.server.getHTMLConfig()
  }

  setTitle (subTitle?: string) {
    let title = ''
    if (subTitle) title += `${subTitle} - `

    title += this.config.instance.name

    this.titleService.setTitle(title)
  }

  setTag (name: string, value: string) {
    this.meta.addTag({ name, content: value })
  }

  update (meta: MetaSettings) {
    this.setTitle(meta.title)
  }
}