From e3ad75d073b7126374feea335f5eef9c3c1f7f3a Mon Sep 17 00:00:00 2001 From: Bastiaan van der Plaat Date: Fri, 12 Jan 2024 19:38:55 +0100 Subject: [PATCH] Ladybird: Move and format directory and error template files --- Base/res/ladybird/directory.html | 51 ---------------- Base/res/ladybird/error.html | 23 ------- Base/res/ladybird/templates/directory.html | 61 +++++++++++++++++++ Base/res/ladybird/templates/error.html | 26 ++++++++ Meta/gn/secondary/Ladybird/BUILD.gn | 4 +- .../LibWeb/Loader/GeneratedPagesLoader.cpp | 12 ++-- 6 files changed, 93 insertions(+), 84 deletions(-) delete mode 100644 Base/res/ladybird/directory.html delete mode 100644 Base/res/ladybird/error.html create mode 100644 Base/res/ladybird/templates/directory.html create mode 100644 Base/res/ladybird/templates/error.html diff --git a/Base/res/ladybird/directory.html b/Base/res/ladybird/directory.html deleted file mode 100644 index aeb9ef8b73..0000000000 --- a/Base/res/ladybird/directory.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - - Index of @path@ - - - -
- -

Index of @path@

-
-

Open Parent Directory

-
- @contents@ -
- - diff --git a/Base/res/ladybird/error.html b/Base/res/ladybird/error.html deleted file mode 100644 index 81a2c5831a..0000000000 --- a/Base/res/ladybird/error.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - Error! - - - -
- Warning -

Failed to load @failed_url@

-
- - diff --git a/Base/res/ladybird/templates/directory.html b/Base/res/ladybird/templates/directory.html new file mode 100644 index 0000000000..ef96bc2f7d --- /dev/null +++ b/Base/res/ladybird/templates/directory.html @@ -0,0 +1,61 @@ + + + + + Index of @path@ + + + +
+ +

Index of @path@

+
+

Open Parent Directory

+
+ @contents@ +
+ + diff --git a/Base/res/ladybird/templates/error.html b/Base/res/ladybird/templates/error.html new file mode 100644 index 0000000000..371d7613c5 --- /dev/null +++ b/Base/res/ladybird/templates/error.html @@ -0,0 +1,26 @@ + + + + + Error! + + + +
+ Warning +

Failed to load @failed_url@

+
+ + diff --git a/Meta/gn/secondary/Ladybird/BUILD.gn b/Meta/gn/secondary/Ladybird/BUILD.gn index 33aef0e58f..6b394757f0 100644 --- a/Meta/gn/secondary/Ladybird/BUILD.gn +++ b/Meta/gn/secondary/Ladybird/BUILD.gn @@ -294,11 +294,11 @@ if (current_os == "mac") { bundle_data("ladybird_web_resources") { sources = [ - "//Base/res/ladybird/directory.html", - "//Base/res/ladybird/error.html", "//Base/res/ladybird/inspector.css", "//Base/res/ladybird/inspector.js", "//Base/res/ladybird/new-tab.html", + "//Base/res/ladybird/templates/directory.html", + "//Base/res/ladybird/templates/error.html", ] outputs = [ "{{bundle_resources_dir}}/res/ladybird/{{source_file_part}}" ] } diff --git a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp index e6f8706fdd..5eb4f8735c 100644 --- a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp @@ -19,13 +19,11 @@ ErrorOr load_error_page(AK::URL const& url) { // Generate HTML error page from error template file // FIXME: Use an actual templating engine (our own one when it's built, preferably with a way to check these usages at compile time) - auto template_path = TRY(Core::Resource::load_from_uri("resource://ladybird/error.html"sv))->filesystem_path(); - auto template_file = TRY(Core::File::open(template_path, Core::File::OpenMode::Read)); - auto template_contents = TRY(template_file->read_until_eof()); + auto template_file = TRY(Core::Resource::load_from_uri("resource://ladybird/templates/error.html"sv)); StringBuilder builder; SourceGenerator generator { builder }; generator.set("failed_url", url.to_byte_string()); - generator.append(template_contents); + generator.append(template_file->data()); return TRY(String::from_utf8(generator.as_string_view())); } @@ -60,15 +58,13 @@ ErrorOr load_file_directory_page(AK::URL const& url) // Generate HTML directory page from directory template file // FIXME: Use an actual templating engine (our own one when it's built, preferably with a way to check these usages at compile time) - auto template_path = TRY(Core::Resource::load_from_uri("resource://ladybird/directory.html"sv))->filesystem_path(); - auto template_file = TRY(Core::File::open(template_path, Core::File::OpenMode::Read)); - auto template_contents = TRY(template_file->read_until_eof()); + auto template_file = TRY(Core::Resource::load_from_uri("resource://ladybird/templates/directory.html"sv)); StringBuilder builder; SourceGenerator generator { builder }; generator.set("path", escape_html_entities(lexical_path.string())); generator.set("parent_url", TRY(String::formatted("file://{}", escape_html_entities(lexical_path.parent().string())))); generator.set("contents", contents.to_byte_string()); - generator.append(template_contents); + generator.append(template_file->data()); return TRY(String::from_utf8(generator.as_string_view())); }