Skip to content
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

Simple console error message dialog in zola serve webpages #2312

Merged
merged 3 commits into from
Sep 25, 2023
Merged

Simple console error message dialog in zola serve webpages #2312

merged 3 commits into from
Sep 25, 2023

Conversation

grantshandy
Copy link
Contributor

Resolves #2303.

screenshot

This PR creates a mutable static error variable in crate::cmd::serve, and inserts a console-like error message dialog onto all outgoing HTML responses. The actual implementation is a little sub-optimal, but it's the best I could do considering two different threads have to share state between 4+ nested FnMut()s.

I tried to make the message dialog as neutral as possible, if there are any zola-specific styles it should have, let me know :)

Copy link
Collaborator

@Keats Keats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that a lot!

let html_error = format!(
r#"<div style="all:revert;position:fixed;display:flex;align-items:center;justify-content:center;background-color:rgb(0,0,0,0.5);top:0;right:0;bottom:0;left:0;"><div style="background-color:white;padding:0.5rem;border-radius:0.375rem;filter:drop-shadow(0,25px,25px,rgb(0,0,0/0.15));overflow-x:auto;"><p style="font-weight:700;color:black;font-size:1.25rem;margin:0;margin-bottom:0.5rem;">Zola Build Error:</p><pre style="padding:0.5rem;margin:0;border-radius:0.375rem;background-color:#363636;color:#CE4A2F;font-weight:700;">{error_str}</pre></div></div>"#
);
bytes.extend(html_error.as_bytes());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get some invalid HTML generated by inserting after </html>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this way is technically invalid HTML, but it worked on all the browsers I tested it on. If that's too much of a problem I can try to remove </html> before appending the message box 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it works on all browsers it's fine, not the weirdest HTML they will see

@Keats Keats merged commit 6a612ca into getzola:master Sep 25, 2023
5 checks passed
@Keats
Copy link
Collaborator

Keats commented Sep 25, 2023

Thanks!

technimad pushed a commit to technimad/zola that referenced this pull request Sep 30, 2023
…#2312)

* first attempt at injecting HTML into outgoing webpages

* finish error handling

* fix test_site debug line
Drodt pushed a commit to DerDrodt/zola that referenced this pull request Oct 10, 2023
…#2312)

* first attempt at injecting HTML into outgoing webpages

* finish error handling

* fix test_site debug line
fredr pushed a commit to fredr/zola that referenced this pull request Oct 21, 2023
…#2312)

* first attempt at injecting HTML into outgoing webpages

* finish error handling

* fix test_site debug line
selfisekai pushed a commit to selfisekai/zola that referenced this pull request Nov 3, 2023
…#2312)

* first attempt at injecting HTML into outgoing webpages

* finish error handling

* fix test_site debug line
Newbytee pushed a commit to Newbytee/zola that referenced this pull request Dec 19, 2023
…#2312)

* first attempt at injecting HTML into outgoing webpages

* finish error handling

* fix test_site debug line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Show zola serve errors in web browser.
2 participants