Skip to content

Commit 74a1a6a

Browse files
committed
feat: hide Blog under flag
1 parent 74611c4 commit 74a1a6a

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

src/app/app.routes.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { Routes } from '@angular/router';
1+
import { inject } from '@angular/core';
2+
import { CanMatchFn, Routes } from '@angular/router';
3+
import { DebugService } from './services/debug.service';
4+
5+
const debugGuard: CanMatchFn = () => inject(DebugService).isEnabled;
26

37
export const routes: Routes = [
48
{
@@ -7,6 +11,7 @@ export const routes: Routes = [
711
},
812
{
913
path: 'blog',
14+
canMatch: [debugGuard],
1015
loadComponent: () => import('./pages/blog/blog.component').then((module) => module.BlogComponent),
1116
},
1217
{
@@ -22,6 +27,7 @@ export const routes: Routes = [
2227
},
2328
{
2429
path: 'blog/:id',
30+
canMatch: [debugGuard],
2531
loadComponent: () =>
2632
import('./pages/blog/blog-detail/blog-detail.component').then(
2733
(module) => module.BlogDetailComponent,

src/app/components/header/header.component.html

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,17 @@
9494
>{{ 'nav.about' | transloco }}</a
9595
>
9696
</li>
97-
<li class="block">
98-
<a
99-
routerLink="/blog"
100-
routerLinkActive="text-(--color-primary)"
101-
(click)="closeDropdown($event)"
102-
class="block rounded-[calc(var(--radius)-2px)] px-3 py-2 text-inherit no-underline hover:bg-(--surface)"
103-
>{{ 'nav.blog' | transloco }}</a
104-
>
105-
</li>
97+
@if (debugService.isEnabled) {
98+
<li class="block">
99+
<a
100+
routerLink="/blog"
101+
routerLinkActive="text-(--color-primary)"
102+
(click)="closeDropdown($event)"
103+
class="block rounded-[calc(var(--radius)-2px)] px-3 py-2 text-inherit no-underline hover:bg-(--surface)"
104+
>{{ 'nav.blog' | transloco }}</a
105+
>
106+
</li>
107+
}
106108
<li class="block">
107109
<a
108110
routerLink="/events"
@@ -211,14 +213,16 @@
211213
>{{ 'nav.about' | transloco }}</a
212214
>
213215
</li>
214-
<li class="block">
215-
<a
216-
routerLink="/blog"
217-
(click)="closeDropdown($event)"
218-
class="block rounded-[calc(var(--radius)-2px)] px-3 py-2 text-inherit no-underline hover:bg-(--surface)"
219-
>{{ 'nav.blog' | transloco }}</a
220-
>
221-
</li>
216+
@if (debugService.isEnabled) {
217+
<li class="block">
218+
<a
219+
routerLink="/blog"
220+
(click)="closeDropdown($event)"
221+
class="block rounded-[calc(var(--radius)-2px)] px-3 py-2 text-inherit no-underline hover:bg-(--surface)"
222+
>{{ 'nav.blog' | transloco }}</a
223+
>
224+
</li>
225+
}
222226
<li class="block">
223227
<a
224228
routerLink="/events"

src/app/components/header/header.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/cor
22
import { NgOptimizedImage } from '@angular/common';
33
import { Router, RouterLink, RouterLinkActive } from '@angular/router';
44
import { TranslocoModule, TranslocoService } from '@jsverse/transloco';
5+
import { DebugService } from '../../services/debug.service';
56

67
@Component({
78
selector: 'app-header',
@@ -12,6 +13,7 @@ import { TranslocoModule, TranslocoService } from '@jsverse/transloco';
1213
export class HeaderComponent {
1314
private readonly translocoService = inject(TranslocoService);
1415
private readonly router = inject(Router);
16+
protected readonly debugService = inject(DebugService);
1517
protected readonly activeLang = signal(this.translocoService.getActiveLang());
1618

1719
protected toggleLanguage(): void {

src/app/services/debug.service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { inject, Injectable } from '@angular/core';
2+
import { DOCUMENT } from '@angular/common';
3+
4+
@Injectable({ providedIn: 'root' })
5+
export class DebugService {
6+
private readonly document = inject(DOCUMENT);
7+
8+
readonly isEnabled: boolean =
9+
new URLSearchParams(this.document.defaultView?.location.search ?? '').get('debug') === 'true';
10+
}

0 commit comments

Comments
 (0)