LibWeb+Base: Use AK::SourceGenerator for error pages

Instead of storing a format string in a file, let's be reasonable
and use SourceGenerator's template functionality. :^)
This commit is contained in:
Andreas Kling 2021-04-22 00:00:06 +02:00
parent edf0b14e23
commit 3857148028
2 changed files with 9 additions and 9 deletions

View file

@ -14,8 +14,8 @@
<body> <body>
<header> <header>
<img src="file:///res/icons/32x32/msgbox-warning.png" alt="Warning" width="24" height="24"> <img src="file:///res/icons/32x32/msgbox-warning.png" alt="Warning" width="24" height="24">
<h1>Failed to load {}</h1> <h1>Failed to load @failed_url@</h1>
</header> </header>
<p>Error: {}</p> <p>Error: @error@</p>
</body> </body>
</html> </html>

View file

@ -26,6 +26,7 @@
#include <AK/Debug.h> #include <AK/Debug.h>
#include <AK/LexicalPath.h> #include <AK/LexicalPath.h>
#include <AK/SourceGenerator.h>
#include <LibGemini/Document.h> #include <LibGemini/Document.h>
#include <LibGfx/ImageDecoder.h> #include <LibGfx/ImageDecoder.h>
#include <LibMarkdown/Document.h> #include <LibMarkdown/Document.h>
@ -226,13 +227,12 @@ void FrameLoader::load_error_page(const URL& failed_url, const String& error)
error_page_url, error_page_url,
[this, failed_url, error](auto data, auto&, auto) { [this, failed_url, error](auto data, auto&, auto) {
VERIFY(!data.is_null()); VERIFY(!data.is_null());
#pragma GCC diagnostic ignored "-Wformat-nonliteral" StringBuilder builder;
auto html = String::formatted( SourceGenerator generator { builder };
data, generator.set("failed_url", failed_url.to_string());
escape_html_entities(failed_url.to_string()), generator.set("error", error);
escape_html_entities(error)); generator.append(data);
#pragma GCC diagnostic pop auto document = HTML::parse_html_document(generator.as_string_view(), failed_url, "utf-8");
auto document = HTML::parse_html_document(html, failed_url, "utf-8");
VERIFY(document); VERIFY(document);
frame().set_document(document); frame().set_document(document);
}, },