Closed brandonroberts closed 1 year ago
@brandonroberts just ran into the same issue working on my personal website! I can work on this if you want
That would be great 👍
Awesome! What do you think we should do when no file is found for the current route?
Currently the customFallback
param is returned.
When returning an object we have other options:
export function injectContent<
Attributes extends Record<string, any> = Record<string, any>
>(
param = 'slug',
fallback = 'No Content Found'
): Observable<ContentFile<Attributes> | undefined> {
const route = inject(ActivatedRoute);
const contentFiles = injectContentFiles<Attributes>();
return route.paramMap.pipe(
map((params) => params.get(param)),
map((slug) => {
return contentFiles.find(
(file) => file.filename === `/src/content/${slug}.md`
);
})
);
}
customFallback
as its content
export function injectContent<
Attributes extends Record<string, any> = Record<string, any>
>(
param = 'slug',
fallback = 'No Content Found'
): Observable<ContentFile<Attributes | Record<string, never>>> {
const route = inject(ActivatedRoute);
const contentFiles = injectContentFiles<Attributes | Record<string, never>>();
return route.paramMap.pipe(
map((params) => params.get(param)),
map((slug) => {
return (
contentFiles.find(
(file) => file.filename === `/src/content/${slug}.md`
) || {
attributes: {},
filename: '',
content: fallback,
}
);
})
);
}
Let me know what you think 👍
Option 2 is good to me
Which scope/s are relevant/related to the feature request?
content
Information
Currently if you want to display a single post, you can use the
injectContent()
function to get the rendered markdown as a string. If you want to display the metadata from the content within the component, you basically have to reimplementinjectContent()
to return the content with metadata.The proposed change would return the content with metadata instead of the string itself
Describe any alternatives/workarounds you're currently using
No response
I would be willing to submit a PR to fix this issue