-
Notifications
You must be signed in to change notification settings - Fork 509
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
feat: add prerender:route hook #213
Conversation
src/prerender.ts
Outdated
nitro.logger.log(chalk.gray(` ββ ${route} (${end - start}ms)`)) | ||
nitro.hooks.callHook('prerender:route', { route, contents, filePath }) | ||
} catch (error) { | ||
nitro.logger.log(chalk.gray(` ββ ${route} (${end - start}ms) ${error ? `(${error})` : ''}`)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also allow hook access to the errors rendered with error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback.
I've made the return response of the prerender:route
hook to be an object or an error. I also thought of introducing a hook to handle errors such as prerender:route:error
. If you think it's cleaner to do this, I can make the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking, that by using a single hook, we can allow:
- Custom error (hooking to validate and modify context to extract an error being thrown)
- Clear error (hooking to allow still prerendering some pages with errors)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I'm not sure I have understood correctly, but please let me know if my last changes seems good for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made few more refactors in the same PR to introduce this object I hope it gives some ideas for next steps :)
Thanks! This also resolves #88 |
β€οΈ |
π Linked issue
β Type of change
π Description
Add a new hook
prerender:route
that is called when a single page has been successfully prerendered.This hook can be used externally to create specific logic tied to route generation, such as editing output of a route.
generateRoute
now returns{ contents, route, filePath }
instead of nothing, in order to:filePath
.contents
that have been generated.I can see more potential for SSG (fully static).
A quick example usage could be to dynamically download and replace static assets, stored on an API server, that you don't want to use in production (parse HTML content, download image, replace image path with the one downloaded locally).
Please, let me know if this change is not intended for nitro.
π Checklist