Skip to content

Commit cdacae0

Browse files
authored
fix(content): stripped filename to match filename also for additionalContentDirs (#1962)
1 parent 61cd4a0 commit cdacae0

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// /src/app/pages/blog/posts.[slug].page.ts
2+
import { injectContent, MarkdownComponent } from '@analogjs/content';
3+
import { AsyncPipe } from '@angular/common';
4+
import { Component } from '@angular/core';
5+
6+
export interface PostAttributes {
7+
title: string;
8+
slug: string;
9+
description: string;
10+
coverImage: string;
11+
}
12+
13+
@Component({
14+
standalone: true,
15+
imports: [MarkdownComponent, AsyncPipe],
16+
template: `
17+
@if (post$ | async; as post) {
18+
<h1>{{ post.attributes.title }}</h1>
19+
<analog-markdown [content]="post.content"></analog-markdown>
20+
}
21+
`,
22+
})
23+
export default class BlogPostComponent {
24+
readonly post$ = injectContent<PostAttributes>();
25+
}

packages/content/src/lib/content-files-token.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ export const CONTENT_FILES_TOKEN = new InjectionToken<
3030
Object.entries(allFiles).forEach((entry) => {
3131
const filename = entry[0];
3232
const value = entry[1];
33+
const strippedFilename = filename.replace(
34+
/^\/(.*?)\/content/,
35+
'/src/content',
36+
);
3337

34-
const newFilename = lookup[filename];
38+
const newFilename = lookup[strippedFilename];
3539
if (newFilename !== undefined) {
3640
const objectFilename = newFilename.replace(
3741
/^\/(.*?)\/content/,

0 commit comments

Comments
 (0)