-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Is your feature request related to a problem? Please describe.
Currently it doesn't seem possible to easily share data between your vitepress config and a dynamic paths loader. Nor can you easily share data between a content loader and a dynamic paths loader. It would be nice if this was possible.
A use case for this is when you also want to generate some custom sitemap for your dynamic routes. Or when your data contains a subject and tags and you want to add routes for all. Currently you either have to fetch your dynamic data/routes at least twice or implement fs caching yourself.
Describe the solution you'd like
Some key-value cache / interface so that you can fetch all dynamic routes in your config.ts
, then do whatever you want with the data (fe create a sidebar for those dynamic routes), then re-use the already fetched routes in a some/[dynamic].paths.ts
loader.
A suggested interface could be as simple as:
UserConfig.router.dynamicRouteData: Record<string | symbol, any>
then
- pass UserData from
resolvePages
toresolveDynamicRoutes
indynamicRoutesPlugin
- wrap loader call's and pass
dynamicRouteData
as second argument to the paths loader (first arg is the watched files afaik)
Im not sure if content loaders run before dynamic path loaders? If so then content loaders should probably also have access to this interface
Describe alternatives you've considered
It's not possible to use a virtual:
vite module as the paths loaders are called during vite setup, not during vite build.
Additional context
At the moment I'm using a custom VitePress plugin that fetches data, then writes that data to the .vitepress/cache
folder and use that data in the some/[dynamic].paths.ts
loader. It works, but it's not super nice.
This request is tackling a similar problem as in #2826, but I think a top-down flow (from config to loaders instead of vice versa) is probably the easiest to resolve these cases. It's also similar to the Vue.provide/inject
approach.
Another similar problem, also having to read data from fs twice: #3625
Validations
- Follow our Code of Conduct
- Read the docs.
- Read the Contributing Guidelines.
- Check that there isn't already an issue that asks for the same feature to avoid creating a duplicate.