Skip to content

Commit 3708ed8

Browse files
authored
Merge pull request #3 from laravelcm/meta-data
Add Meta data for SEO
2 parents 3550c36 + 51db849 commit 3708ed8

File tree

16 files changed

+259
-160
lines changed

16 files changed

+259
-160
lines changed
Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,62 @@
11
import { Component, OnInit } from '@angular/core';
22

3+
import { SeoService } from '@app/shared/services/seo.service';
4+
35
@Component({
46
selector: 'admin-root',
57
template: '<router-outlet></router-outlet>',
68
})
79
export class AppComponent implements OnInit {
810
mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
911

12+
public constructor(private seoService: SeoService) {}
13+
14+
ngOnInit(): void {
15+
document.documentElement.setAttribute('data-theme', this.updateTheme());
16+
17+
new MutationObserver(([{ oldValue }]) => {
18+
let newValue = document.documentElement.getAttribute('data-theme')!;
19+
if (newValue !== oldValue) {
20+
try {
21+
window.localStorage.setItem('theme', newValue);
22+
} catch {}
23+
this.updateThemeWithoutTransitions(newValue);
24+
}
25+
}).observe(document.documentElement, {
26+
attributeFilter: ['data-theme'],
27+
attributeOldValue: true,
28+
});
29+
}
30+
1031
updateTheme(savedTheme: string | null = null): string {
11-
let theme = 'system'
32+
let theme = 'system';
1233
try {
1334
if (!savedTheme) {
14-
savedTheme = window.localStorage.getItem('theme')
35+
savedTheme = window.localStorage.getItem('theme');
1536
}
1637
if (savedTheme === 'dark') {
17-
theme = 'dark'
18-
document.documentElement.classList.add('dark')
38+
theme = 'dark';
39+
document.documentElement.classList.add('dark');
1940
} else if (savedTheme === 'light') {
20-
theme = 'light'
21-
document.documentElement.classList.remove('dark')
41+
theme = 'light';
42+
document.documentElement.classList.remove('dark');
2243
} else if (this.mediaQuery.matches) {
23-
document.documentElement.classList.add('dark')
44+
document.documentElement.classList.add('dark');
2445
} else {
25-
document.documentElement.classList.remove('dark')
46+
document.documentElement.classList.remove('dark');
2647
}
2748
} catch {
28-
theme = 'light'
29-
document.documentElement.classList.remove('dark')
49+
theme = 'light';
50+
document.documentElement.classList.remove('dark');
3051
}
31-
return theme
52+
return theme;
3253
}
3354

3455
updateThemeWithoutTransitions(savedTheme: string | null = null): void {
35-
this.updateTheme(savedTheme)
36-
document.documentElement.classList.add('[&_*]:!transition-none')
56+
this.updateTheme(savedTheme);
57+
document.documentElement.classList.add('[&_*]:!transition-none');
3758
window.setTimeout(() => {
38-
document.documentElement.classList.remove('[&_*]:!transition-none')
39-
}, 0)
40-
}
41-
42-
ngOnInit(): void {
43-
document.documentElement.setAttribute('data-theme', this.updateTheme())
44-
45-
new MutationObserver(([{ oldValue }]) => {
46-
let newValue = document.documentElement.getAttribute('data-theme')!
47-
if (newValue !== oldValue) {
48-
try {
49-
window.localStorage.setItem('theme', newValue)
50-
} catch {}
51-
this.updateThemeWithoutTransitions(newValue)
52-
}
53-
}).observe(document.documentElement, { attributeFilter: ['data-theme'], attributeOldValue: true })
59+
document.documentElement.classList.remove('[&_*]:!transition-none');
60+
}, 0);
5461
}
5562
}

src/app/modules/authentication/pages/forgot-password/forgot-password.component.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
22
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3+
import { Meta, Title } from '@angular/platform-browser';
34
import { Store } from '@ngrx/store';
45
import { Observable } from 'rxjs';
56

7+
import { environment } from 'environments/environment';
68
import { forgotPasswordAction } from '../../store/auth.actions';
79
import {
810
selectError,
@@ -13,8 +15,8 @@ import {
1315
@Component({
1416
templateUrl: './forgot-password.component.html',
1517
})
16-
export class ForgotPasswordComponent {
17-
public form: FormGroup = this.formBuilder.group({
18+
export class ForgotPasswordComponent implements OnInit {
19+
public form: FormGroup = this.fb.group({
1820
email: ['', [Validators.required, Validators.email]],
1921
});
2022

@@ -24,7 +26,28 @@ export class ForgotPasswordComponent {
2426

2527
public loading$: Observable<boolean> = this.store.select(selectLoading);
2628

27-
constructor(private formBuilder: FormBuilder, private store: Store) {}
29+
constructor(
30+
private fb: FormBuilder,
31+
private store: Store,
32+
private meta: Meta,
33+
private title: Title
34+
) {}
35+
36+
ngOnInit(): void {
37+
this.title.setTitle($localize`Mot de passe oublié | Admin CPanel`);
38+
this.meta.updateTag({
39+
property: 'og:url',
40+
content: environment.baseUrl + '/forgot-password',
41+
});
42+
this.meta.updateTag({
43+
property: 'og:title',
44+
content: $localize`Mot de passe oublié | Admin CPanel`,
45+
});
46+
this.meta.updateTag({
47+
property: 'og:description',
48+
content: $localize`Réinitialisez votre mot de passe`,
49+
});
50+
}
2851

2952
public submit() {
3053
if (this.form.valid) {

src/app/modules/authentication/pages/login/login.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ <h2 class="mt-6 text-3xl font-semibold text-slate-900 dark:text-white" i18n>Conn
3636

3737
<div class="flex items-center justify-between">
3838
<label for="remember-me" class="flex items-center cursor-pointer">
39-
<input id="remember-me" name="remember-me" type="checkbox" class="w-4 h-4 rounded text-primary-600 border-slate-300 focus:ring-primary-500">
39+
<input id="remember-me" name="remember-me" type="checkbox" class="w-4 h-4 bg-white rounded text-primary-600 border-slate-300 focus:ring-primary-500 dark:bg-gray-800 dark:border-slate-700 dark:focus:ring-offset-gray-800">
4040
<span class="block ml-2 text-sm text-slate-700 dark:text-slate-300" i18n>Se souvenir de moi</span>
4141
</label>
4242

src/app/modules/authentication/pages/login/login.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
templateUrl: './login.component.html',
1515
})
1616
export class LoginComponent {
17-
public form: FormGroup = this.formBuilder.group({
17+
public form: FormGroup = this.fb.group({
1818
email: ['', [Validators.required, Validators.email]],
1919
password: ['', Validators.required],
2020
});
@@ -25,7 +25,7 @@ export class LoginComponent {
2525

2626
public loading$: Observable<boolean> = this.store.select(selectLoading);
2727

28-
constructor(private formBuilder: FormBuilder, private store: Store) {}
28+
constructor(private fb: FormBuilder, private store: Store) {}
2929

3030
public submit() {
3131
if (this.form.valid) {
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component } from '@angular/core';
2+
import { Title } from '@angular/platform-browser';
23

34
@Component({
45
templateUrl: './dashboard.component.html',
56
})
6-
export class DashboardComponent implements OnInit {
7-
8-
constructor() { }
9-
10-
ngOnInit(): void {
11-
}
12-
7+
export class DashboardComponent {
8+
constructor(private title: Title) {}
139
}

src/app/modules/index.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/app/shared/components/buttons/default.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { Observable } from 'rxjs';
88
[type]="type"
99
[disabled]="loading$ | async"
1010
[ngClass]="class"
11-
class="inline-flex items-center px-4 py-2 text-sm font-medium bg-white border rounded-md shadow-sm border-slate-300 text-slate-600 hover:bg-slate-50 hover:text-slate-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2">
11+
class="inline-flex items-center px-4 py-2 text-sm font-medium bg-white border rounded-md shadow-sm border-slate-300 text-slate-600 hover:bg-slate-50 hover:text-slate-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 dark:bg-gray-700 dark:hover:bg-gray-800 dark:text-slate-300 dark:hover:text-white dark:focus:ring-offset-gray-800">
1212
<span *ngIf="loading$ | async">
1313
<svg
14-
class="w-5 h-5 mr-3 -ml-1 text-slate-500 animate-spin"
14+
class="w-5 h-5 mr-3 -ml-1 text-slate-500 dark:text-slate-400 animate-spin"
1515
fill="none"
1616
viewBox="0 0 24 24">
1717
<circle

src/app/shared/components/buttons/link.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Component, Input } from '@angular/core';
66
<a
77
[routerLink]="link"
88
[ngClass]="class"
9-
class="inline-flex items-center rounded-md border border-transparent bg-primary-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2">
9+
class="inline-flex items-center rounded-md border border-transparent bg-primary-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 dark:bg-gray-700 dark:hover:bg-gray-800 dark:text-slate-300 dark:hover:text-white dark:focus:ring-offset-gray-800">
1010
<ng-content></ng-content>
1111
</a>
1212
`,

src/app/shared/components/buttons/primary.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Observable } from 'rxjs';
77
<button
88
[type]="type"
99
[disabled]="loading$ | async"
10-
class="relative inline-flex items-center px-4 py-2 text-sm font-medium text-white bg-primary-600 hover:bg-primary-700 focus:ring-primary-500 border border-transparent rounded-md shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed transition ease-in-out duration-150"
10+
class="relative inline-flex items-center px-4 py-2 text-sm font-medium text-white bg-primary-600 hover:bg-primary-700 focus:ring-primary-500 border border-transparent rounded-md shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed transition ease-in-out duration-150 dark:focus:ring-offset-gray-800"
1111
[ngClass]="class"
1212
matRipple
1313
matRippleColor="primary">

src/app/shared/components/simple-drawer/button.component.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/app/shared/components/simple-drawer/simple-drawer.component.html

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/app/shared/components/simple-drawer/simple-drawer.component.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/app/shared/helpers/meta-data.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { environment } from 'environments/environment';
2+
3+
export const siteTitle = environment.appName;
4+
5+
export interface SeoInterface {
6+
[key: string]: {
7+
title: string;
8+
description?: string;
9+
keywords?: string;
10+
metaTags?: {
11+
[key: string]: string;
12+
};
13+
};
14+
}
15+
16+
export const meta: SeoInterface = {
17+
'/auth/login': {
18+
title: $localize`Connexion | ${siteTitle}`,
19+
description: $localize`Connexion à votre compte`,
20+
keywords: $localize`connexion, compte, admin, cpanel`,
21+
metaTags: {
22+
'og:url': `${environment.baseUrl}/auth/login`,
23+
},
24+
},
25+
'/auth/forgot-password': {
26+
title: $localize`Mot de passe oublié | ${siteTitle}`,
27+
description: $localize`Réinitialisez votre mot de passe`,
28+
keywords: $localize`mot de passe, oublié, admin, cpanel`,
29+
metaTags: {
30+
'og:url': `${environment.baseUrl}/auth/forgot-password`,
31+
},
32+
},
33+
'/dashboard': {
34+
title: $localize`Tableau de bord | ${siteTitle}`,
35+
description: $localize`Tableau de bord`,
36+
keywords: $localize`tableau de bord, admin, cpanel`,
37+
metaTags: {
38+
'og:url': `${environment.baseUrl}/dashboard`,
39+
},
40+
},
41+
};

0 commit comments

Comments
 (0)