From 0f01a8bacddf6c502e6470e34fdac7750bb76e89 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 14 May 2021 16:12:45 +0200 Subject: Remove ngx-meta Unmaintained --- client/src/app/core/core.module.ts | 7 ++-- client/src/app/core/routing/index.ts | 2 ++ client/src/app/core/routing/meta-guard.service.ts | 23 +++++++++++++ client/src/app/core/routing/meta.service.ts | 40 +++++++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 client/src/app/core/routing/meta-guard.service.ts create mode 100644 client/src/app/core/routing/meta.service.ts (limited to 'client/src/app/core') diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts index 3152a7003..de3274544 100644 --- a/client/src/app/core/core.module.ts +++ b/client/src/app/core/core.module.ts @@ -14,7 +14,7 @@ import { throwIfAlreadyLoaded } from './module-import-guard' import { Notifier } from './notification' import { HtmlRendererService, LinkifierService, MarkdownService } from './renderer' import { RestExtractor, RestService } from './rest' -import { LoginGuard, RedirectService, UnloggedGuard, UserRightGuard } from './routing' +import { LoginGuard, MetaGuard, MetaService, RedirectService, UnloggedGuard, UserRightGuard } from './routing' import { CanDeactivateGuard } from './routing/can-deactivate-guard.service' import { ServerConfigResolver } from './routing/server-config-resolver.service' import { ScopedTokensService } from './scoped-tokens' @@ -77,7 +77,10 @@ import { LocalStorageService, ScreenService, SessionStorageService } from './wra MessageService, PeerTubeSocket, ServerConfigResolver, - CanDeactivateGuard + CanDeactivateGuard, + + MetaService, + MetaGuard ] }) export class CoreModule { diff --git a/client/src/app/core/routing/index.ts b/client/src/app/core/routing/index.ts index 239c27caf..4314ea475 100644 --- a/client/src/app/core/routing/index.ts +++ b/client/src/app/core/routing/index.ts @@ -3,6 +3,8 @@ export * from './custom-reuse-strategy' export * from './disable-for-reuse-hook' export * from './login-guard.service' export * from './menu-guard.service' +export * from './meta-guard.service' +export * from './meta.service' export * from './preload-selected-modules-list' export * from './redirect.service' export * from './server-config-resolver.service' diff --git a/client/src/app/core/routing/meta-guard.service.ts b/client/src/app/core/routing/meta-guard.service.ts new file mode 100644 index 000000000..bedb3450e --- /dev/null +++ b/client/src/app/core/routing/meta-guard.service.ts @@ -0,0 +1,23 @@ +import { Injectable } from '@angular/core' +import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, RouterStateSnapshot } from '@angular/router' +import { MetaService } from './meta.service' + +@Injectable() +export class MetaGuard implements CanActivate, CanActivateChild { + + constructor (private meta: MetaService) { } + + canActivate (route: ActivatedRouteSnapshot): boolean { + const metaSettings = route.data?.meta + + if (metaSettings) { + this.meta.update(metaSettings) + } + + return true + } + + canActivateChild (route: ActivatedRouteSnapshot): boolean { + return this.canActivate(route) + } +} diff --git a/client/src/app/core/routing/meta.service.ts b/client/src/app/core/routing/meta.service.ts new file mode 100644 index 000000000..a5ac778dc --- /dev/null +++ b/client/src/app/core/routing/meta.service.ts @@ -0,0 +1,40 @@ +import { Injectable } from '@angular/core' +import { Meta, Title } from '@angular/platform-browser' +import { HTMLServerConfig } from '@shared/models/server' +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.getTmpConfig() + this.server.getConfig() + .subscribe(config => this.config = config) + } + + 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) + } +} -- cgit v1.2.3