1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:58:13 +00:00

LibWeb: Use resources to find internal HTML template paths

This commit is contained in:
Bastiaan van der Plaat 2023-12-26 10:24:05 +01:00 committed by Tim Flynn
parent f8feca5d21
commit 009729d5e3
5 changed files with 3 additions and 40 deletions

View file

@ -9,40 +9,17 @@
#include <AK/SourceGenerator.h>
#include <LibCore/DateTime.h>
#include <LibCore/Directory.h>
#include <LibCore/Resource.h>
#include <LibCore/System.h>
#include <LibWeb/Loader/GeneratedPagesLoader.h>
namespace Web {
static String s_error_page_url = "file:///res/ladybird/error.html"_string;
String error_page_url()
{
return s_error_page_url;
}
void set_error_page_url(String error_page_url)
{
s_error_page_url = error_page_url;
}
static String s_directory_page_url = "file:///res/ladybird/directory.html"_string;
String directory_page_url()
{
return s_directory_page_url;
}
void set_directory_page_url(String directory_page_url)
{
s_directory_page_url = directory_page_url;
}
ErrorOr<String> 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 = AK::URL::create_with_url_or_path(error_page_url().to_byte_string()).serialize_path();
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());
StringBuilder builder;
@ -83,7 +60,7 @@ ErrorOr<String> 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 = AK::URL::create_with_url_or_path(directory_page_url().to_byte_string()).serialize_path();
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());
StringBuilder builder;