core
core copied to clipboard
refactor(theme-default): set theme data in client config (close #946)
close #946
BREAKING CHANGE: now you should set default theme locales data in .vuepress/client.ts via defineThemeData
BREAKING CHANGE: now plugin-theme-data does not need options anymore
@meteorlxy Anxiously waiting for this one to come through, will be an amazing change 💯
@meteorlxy Any chance of this getting some love? It's been a few months.
Busy working these days. Will be back to this soon.
We shall not remove the old plugin as it's total reasonale to read the options both side.
Some options may related to temp file generating and assets handling.
Examples
Tree shakable
A simple example is editLink for @vuepress/theme-default, overriding it in pages is a rare case, and in most cases we are expecting users to set it globally.
So for a third party theme, it might drop frontmatter support, so that when users set editLink: false in options, the theme no longer need to append filePathRelative information to page data in extendsPage hook.
The above example is simple, but actions like this can improve "Tree shaking" ability and reduce the final output bundle size. Any global option controlling something all have a chance to do some "tree shakable" work, droping unneeded code.
Node based operations
Some features may related to node based api, and can not be handled at client side, for example, my theme vuepress-theme-hope has a feature called "Structured Sidebar", which generate sidebar from file structure automatically. in such cases, users options must be parsed into node side, then passed to client side after edited.
So I suggest @meteorlxy reconsidered plugin-theme-data rebuilt, old features and behaviors can be (and should be ) preserved when adding the new one.
@Mister-Hope | @meteorlxy
All it needs to allow for that i need myself, is that if add a new MD file that it automatically picks it up, the navigation bar automatically updates and that it doesn't need a server restart for it.
I also get the files automatically tree into the navigation, but every time i do it required a restart to display on the menu, this does not make sense, it should be automatic and dynamic, as long as we can achieve that then i'm satisfied.
Ofcourse, however you guys decide to go about it, if it's part of a greater change, it would be very helpful.. it's desperately needed.
@Mister-Hope I've been scratching my head at this for a while and I've tried a lot of ways to get past it, but it seems like i just can't get the navigation to be dynamic.
Do you have any suggestions that i can try to temporarily alleviate the problem, this wasn't a issue in webpack because of hot reload but in vite this is a problem because i can't access the hot reload in the config.
Even if it means that the server restarts after a new page at this point i have to manually do that, do you have any ideas that i can use besides re-making the entire navigation?
- Injecting navigation items and manually enforce this to occur
- Forcing server restart to occur (via script)
Watchers don't detect or should i say trigger the navigation to update in the config so i'm at a loss.
What i'm trying to do:
Adding a page should automatically be added to the navigation without restarting it, but if it does need a restart (for now) for it to be automatic.
The problem is that pageRoutes can not be hmred, so if you add new page, a restart is expected.
@Mister-Hope What can i use to enforce a restart in this case then? e.g code calls function > tells server to restart/reload.
@Mister-Hope I'm kind of facing the same problem, but even more basic. All I want to do is fetch pages from a CMS and add them to the navigation bar, but I can't find a way to modify the navbar programmatically. How did you go about this?
@Radiergummi A alternative is to remake the navigation, i did so for mine and i use a json to fill the gap, json being generated by a listener.
But i agree, shouldn't be the case and VuePress should be able to do it Programatically even if i inject it.
Closing as we have migrated default theme into another repo