-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support custom pages through theme packs #681
Comments
A couple options I attempted at the moment, as we don't have support for #21 yet. Using a ResourceOne option I tried was using ResolveOne way could be to just "hijack" the path to class ThemePackPageOverrideResource extends ResourceInterface {
constructor(compilation, options) {
super(compilation, options);
this.extensions = ['.html'];
}
async shouldResolve(url) {
console.debug('ThemePackPageOverrideResource shouldResolve', url)
return Promise.resolve(url.replace(this.compilation.context.userWorkspace, '') === '/');
}
async resolve(url) {
return Promise.resolve(path.join(__dirname, 'dist/pages/index.html'));
}
} However, it looks like Greenwood heavily filters what counts as a page so maybe we have to add some sort of "simple" check like path.extname(url) === 'html' && fs.existsSync(url) After getting it to work
seeing this issue now running
InterceptTrying to class ThemePackPageOverrideResource extends ResourceInterface {
constructor(compilation, options) {
super(compilation, options);
this.extensions = ['*'];
}
async shouldIntercept(url) {
console.debug('ThemePackPageOverrideResource shouldIntercept', url)
return Promise.resolve(url.replace(this.compilation.context.userWorkspace, '') === '/');
}
async intercept(url) {
console.debug('ThemePackPageOverrideResource intercept', url)
return Promise.resolve({ body: 'hello world!'});
}
} This means that you get the content of index.html but without
So this just means that the plugin author just has to merge the content of their own index.html into the default returned by Greenwood. I suppose since Greenwood bring along with it an html parser, plugins could piggy back off this and do it just like Greenwood does it? TemplatesAnother quick option, the would require user "intervention" is by publishing index.html as a template and then having the user specify that in their project. src/
assets/
background.png
pages/
index.md
slides/
1.md
2.md
.
.
styles/
overrides.css index.md ---
template: 'index'
--- Naturally the downside here is the user has to do something on their side, but it's a pretty low effort / impact step, and is explicit, as opposed to the above solution, which is very much implicit. However, in this case, this isn't really a template, it's the home / landing page so... 🤷♂️ I suppose the better alternative will be when we can allow direct users of Greenwood to push content directly into the graph, but I think it doesn't necessarily hurts if Greenwood is robust enough to allow for a large degree of flexibility in how its APIs are used. As long as they are clear and stable and consistent, it should be a net positive for everyone. Either way, here are something we can document for now at least. |
Type of Change
Summary
Coming out of #570 / #669 was that currently Context plugins (or more specifically theme packs) are limited to just providing additional templates/ directories. Although Greenwood can effectively resolve anything during development, it can only build pages that are part of its graph, so being able to ship an actual page as part of a plugin is not possible and is already being tracked as part of #21 . (so this may be more of a reminder to update the docs / examples is all, but may require some work as well, we shall see)
Details
For example, like in greenwood-starter-presentation I would like to provide the actual home / landing / index.html page for users, to act as the entire interface to all their content (slides).
So from a user perspective, they would literally only have this for their directory layout, with everything else coming from the plugin (note: you can pull in overrides on a per page already! 💥 )
Literally a user would only actually have this in their repo
The text was updated successfully, but these errors were encountered: