feat(cms): add static pages module
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { ChangeDetectionStrategy, Component, SecurityContext, inject, signal } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, DestroyRef, SecurityContext, effect, inject, signal } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { ActivatedRoute, RouterLink } from '@angular/router';
|
||||
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
|
||||
import { DomSanitizer, Meta, SafeHtml, Title } from '@angular/platform-browser';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { StaticPageResolverService } from '../../core/config/static-page-resolver.service';
|
||||
import { LanguageService } from '../../services/language.service';
|
||||
import { TranslatePipe } from '../../i18n/translate.pipe';
|
||||
@@ -16,29 +17,50 @@ import { TranslatePipe } from '../../i18n/translate.pipe';
|
||||
})
|
||||
export class StaticPageComponent {
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private readonly sanitizer = inject(DomSanitizer);
|
||||
private readonly staticPageResolver = inject(StaticPageResolverService);
|
||||
private readonly languageService = inject(LanguageService);
|
||||
private readonly titleService = inject(Title);
|
||||
private readonly meta = inject(Meta);
|
||||
|
||||
readonly loading = signal(true);
|
||||
readonly notFound = signal(false);
|
||||
readonly title = signal('');
|
||||
readonly homeRoute = signal('');
|
||||
readonly dir = signal<'ltr' | 'rtl'>('ltr');
|
||||
readonly safeHtml = signal<SafeHtml>(this.sanitizer.bypassSecurityTrustHtml(''));
|
||||
|
||||
constructor() {
|
||||
this.homeRoute.set(`/${this.languageService.currentLanguage()}`);
|
||||
private lastKey: string | null = null;
|
||||
private lastPath: string | null = null;
|
||||
|
||||
this.route.paramMap.subscribe(params => {
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const lang = this.languageService.currentLanguage();
|
||||
this.homeRoute.set(`/${lang}`);
|
||||
this.dir.set(['ar', 'fa', 'he', 'ur'].includes(lang) ? 'rtl' : 'ltr');
|
||||
|
||||
if (this.lastKey) {
|
||||
this.loadByKey(this.lastKey);
|
||||
} else if (this.lastPath) {
|
||||
this.loadByPath(this.lastPath);
|
||||
}
|
||||
});
|
||||
|
||||
this.route.paramMap.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(params => {
|
||||
const keyFromParam = params.get('key');
|
||||
const staticPath = params.get('staticPath');
|
||||
|
||||
if (keyFromParam) {
|
||||
this.lastKey = keyFromParam;
|
||||
this.lastPath = null;
|
||||
this.loadByKey(keyFromParam);
|
||||
return;
|
||||
}
|
||||
|
||||
if (staticPath) {
|
||||
this.lastKey = null;
|
||||
this.lastPath = `/${staticPath}`;
|
||||
this.loadByPath(`/${staticPath}`);
|
||||
return;
|
||||
}
|
||||
@@ -72,6 +94,7 @@ export class StaticPageComponent {
|
||||
this.safeHtml.set(this.sanitizer.bypassSecurityTrustHtml(''));
|
||||
this.notFound.set(true);
|
||||
this.loading.set(false);
|
||||
this.titleService.setTitle('404');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -80,5 +103,7 @@ export class StaticPageComponent {
|
||||
this.safeHtml.set(this.sanitizer.bypassSecurityTrustHtml(sanitized));
|
||||
this.notFound.set(false);
|
||||
this.loading.set(false);
|
||||
this.titleService.setTitle(title);
|
||||
this.meta.updateTag({ name: 'description', content: title });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user