-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement a rendering pipeline with middleware (adds support for Brotli and Gzip, cleans up minification) #3007
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
base: next
Are you sure you want to change the base?
Conversation
* `write_content` isn't smart enough to do what we need. * this is a cleaner architecture. * Now pages with txt templates are not minified. * Add test for text template whitespace preservation with minification * Test verifies that non-HTML templates (e.g., .txt) preserve whitespace * Created text_content.txt template with multiple spaces, tabs, and newlines * Created test page using the text template * Test passes with the minification fix (ed36c1e6) and fails without it * Updated page count assertions due to new test page
Now all rendering is followed up with a pipeline of middlewares which is aware of context. Minify and livereload are now middlewares in this pipeline. Everything rendered goes through the same pipeline. This infrastructure will easily support compression and encryption.
35f306c to
9a81c46
Compare
Closes: getzola#1684 (gzip); getzola#1520 (brotli)
This does not compress on the fly. We should consider adding that as an argument to --serve to. This only serves the compressed files zola generates
Previously the middleware could only produce one text, and one binary file. Now this limitation is gone. We can produce multiple text and binary files.
Use WebAssembly for argon2, and Web Crypto API to decrypt. Support modes of encryption based on paths and implement with middleware. * Direct key (env) * Password supplying (uses Argon2) (env, or `config.toml`) * Key generation In the future we may also introduce a nice-password generator but for now this proves out the idea. See ENCRYPTION.md for more information on the middleware. Closes getzola#2993
|
@Keats if you determine this architecture isn't something you want to move towards, please tell me so I can make adjustments or quit closing out issues. |
|
Seems really cool, but the current MR is a lot for a human to digest. |
Fair and certainly doable. Because the architecture isn't cleanly in one patch it makes this patch even more complex. I tweak it a few times. If this is needed. what I can do is rewrite the the patches entirely to sink the commits separately. It's a waste of time though if that's not needed. Actually if the middlewares themselves had their own config parser, they would be entirely self-contained and this would be trivial.. The next patch that I want to do pulls out markdown rendering putting that into the middleware too. And closes out #2930, and #2420 and #2790. This would make adding first-class Tyrst the same way trivial. |
|
It is indeed way too big to review. A few other things:
|
|
I'll get back this and rebase the patch to make it easier to process. I got one more project I have to get off my plate. The architectural changes, should make all the middle wares one file (or relatively small) so you can pick whatever middleware you want. |
I've updated this architecture to support a rendering pipeline which everything goes through.
At the end of every pipeline we call
write(). It's no longer called as IO call at the end of a function (which only know it was writing anindex.html, and thus would minify.txt). This works and passes all tests,With this infrastructure, this patch
zola serve#1684AI summary of patch..
Core Architecture
Key Components
a. Render: Template → String (via Tera)
b. Metadata: Extract path, content type, permalink
c. Context: Wrap in MiddlewareContext
d. Middleware Chain: Sequential transformations
e. Return: ProcessedContent ready to write
Design Benefits
Before vs After
Before: Rendering logic scattered, minification/livereload handled per-type
After: Single pipeline with pluggable middleware - every rendered item flows through the same chain
This architecture mirrors common web frameworks (Express.js middleware, ASP.NET pipeline) and provides a clean foundation for adding post-processing features like
compression or encryption.
write_contentisn't smart enough to do what we need.Addresses #3006