|
| 1 | +import { Component, computed, effect, inject } from '@angular/core'; |
| 2 | +import { ActivatedRoute } from '@angular/router'; |
| 3 | +import { toSignal } from '@angular/core/rxjs-interop'; |
| 4 | +import { contentFileResource } from '@analogjs/content/resources'; |
| 5 | +import { JsonPipe } from '@angular/common'; |
| 6 | +import { MarkdownComponent, injectContentFileLoader } from '@analogjs/content'; |
| 7 | + |
| 8 | +@Component({ |
| 9 | + selector: 'app-docs-optional-catchall-page', |
| 10 | + standalone: true, |
| 11 | + |
| 12 | + template: ` |
| 13 | + <h2>Page template</h2> |
| 14 | + <p>Segments: {{ slug() }}</p> |
| 15 | + <p>Filepath: {{ filePath() }}</p> |
| 16 | + @let page = source.value(); |
| 17 | + @if (page) { |
| 18 | + <pre>{{ page | json }}</pre> |
| 19 | + <analog-markdown [content]="page.content"></analog-markdown> |
| 20 | + } |
| 21 | + `, |
| 22 | + imports: [MarkdownComponent, JsonPipe], |
| 23 | +}) |
| 24 | +export default class DocsOptionalCatchAllPageComponent { |
| 25 | + private readonly route = inject(ActivatedRoute); |
| 26 | + private paramMap = toSignal(this.route.paramMap, { |
| 27 | + initialValue: this.route.snapshot.paramMap, |
| 28 | + }); |
| 29 | + |
| 30 | + readonly slug = computed(() => this.paramMap().get('slug') ?? ''); |
| 31 | + readonly filePath = computed(() => 'docs/' + this.slug()); |
| 32 | + // readonly filePath = computed(() => 'docs/' + (this.slug() || 'index')); |
| 33 | + readonly source = contentFileResource(this.filePath); |
| 34 | + constructor() { |
| 35 | + effect(() => { |
| 36 | + console.log('slug from route params', this.slug()); |
| 37 | + }); |
| 38 | + const load = injectContentFileLoader(); |
| 39 | + load().then((files) => { |
| 40 | + console.log( |
| 41 | + 'Analog content available keys:', |
| 42 | + Object.keys(files).slice(0, 50), |
| 43 | + ); |
| 44 | + }); |
| 45 | + } |
| 46 | +} |
0 commit comments