Closed gergobergo closed 1 year ago
You cannot define glob paths dynamically at runtime. So it would have to be a filter. It's a reasonable change though.
You can filter the array of returned files also
const posts = injectContentFiles().filter(someFilter)
I think passing a callback function for a filter would work and be flexible enough to use in different ways
Sounds good to me. I think the signature of the filter method can be passed as a predicate function. I will prepare a PR for this.
The related PR is here: https://github.com/analogjs/analog/pull/348
Which scope/s are relevant/related to the feature request?
content
Information
Currently, when we run the
injectContentFiles
function, we collect all the available files from thecontent
folder. I would like to suggest a way, that only the files from the specified subdirectory are returned.Proposed API change:
function injectContentFiles<Attributes extends Record<string, any>>(options?: { subdirectory?: string }): ContentFile<Attributes>[]
As I see the current implementation comes with the
InjectionToken
factory. We cannot pass an argument to the factory function so some workaround needs to be done here. One possible solution is to have a service that stores thesubdirectory
value, and we use theinject
function to access this service when we call thegetContentFilesList
function.We can change this file to accept a subdirectory value like this:
Describe any alternatives/workarounds you're currently using
Currently I think the only workaround is to get all the files, and filter the array for the specific folder files.
I would be willing to submit a PR to fix this issue