From e99e386a5f3276745bfbd3c17555a6062d53b72f Mon Sep 17 00:00:00 2001 From: lovasoa Date: Sun, 23 Jun 2024 18:10:10 +0200 Subject: [PATCH] include a default favicon in sqlpage this fixes the Unable to read file "favicon.ico" error that was displayed by default in the console when opening a page in a browser --- CHANGELOG.md | 1 + build.rs | 1 + sqlpage/favicon.svg | 11 +++++++++++ sqlpage/templates/shell.handlebars | 4 +--- src/template_helpers.rs | 1 + src/webserver/http.rs | 1 + src/webserver/static_content.rs | 4 ++++ 7 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 sqlpage/favicon.svg diff --git a/CHANGELOG.md b/CHANGELOG.md index b6cca987..edba6d7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ - New `max_pending_rows` [configuration option](https://sql.ophir.dev/configuration.md) to limit the number of messages that can be sent to the client before they are read. Usefule when sending large amounts of data to slow clients. - Update sqlite to v3.46: https://www.sqlite.org/releaselog/3_46_0.html - Faster initial page load. SQLPage used to wait for the first component to be rendered before sending the shell to the client. We now send the shell immediately, and the first component as soon as it is ready. This can make the initial page load faster, especially when the first component requires a long computation on the database side. + - Include a default favicon when none is specified in the shell component. This fixes the `Unable to read file "favicon.ico"` error message that would appear in the logs by default. ## 0.23.0 (2024-06-09) diff --git a/build.rs b/build.rs index 81fa46f2..3f09fbaa 100644 --- a/build.rs +++ b/build.rs @@ -20,6 +20,7 @@ async fn main() { spawn(download_deps(c.clone(), "tabler-icons.svg")), spawn(download_deps(c.clone(), "apexcharts.js")), spawn(download_deps(c.clone(), "tomselect.js")), + spawn(download_deps(c.clone(), "favicon.svg")), ] { h.await.unwrap(); } diff --git a/sqlpage/favicon.svg b/sqlpage/favicon.svg new file mode 100644 index 00000000..9c67faf6 --- /dev/null +++ b/sqlpage/favicon.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/sqlpage/templates/shell.handlebars b/sqlpage/templates/shell.handlebars index 9b8200a1..f9d18ada 100644 --- a/sqlpage/templates/shell.handlebars +++ b/sqlpage/templates/shell.handlebars @@ -3,9 +3,7 @@ {{default title "SQLPage"}} - {{#if favicon}} - - {{/if}} + {{#if manifest}} {{/if}} diff --git a/src/template_helpers.rs b/src/template_helpers.rs index 7754498b..7a6b9a63 100644 --- a/src/template_helpers.rs +++ b/src/template_helpers.rs @@ -151,6 +151,7 @@ impl CanHelp for StaticPathHelper { "sqlpage.css" => static_filename!("sqlpage.css"), "apexcharts.js" => static_filename!("apexcharts.js"), "tomselect.js" => static_filename!("tomselect.js"), + "favicon.svg" => static_filename!("favicon.svg"), other => return Err(format!("unknown static file: {other:?}")), }; Ok(format!("{}{}", self.0, path).into()) diff --git a/src/webserver/http.rs b/src/webserver/http.rs index 5ced10de..a03dd26f 100644 --- a/src/webserver/http.rs +++ b/src/webserver/http.rs @@ -525,6 +525,7 @@ pub fn create_app( .service(static_content::tomselect_js()) .service(static_content::css()) .service(static_content::icons()) + .service(static_content::favicon()) .default_service(fn_service(main_handler)), ) // when receiving a request outside of the prefix, redirect to the prefix diff --git a/src/webserver/static_content.rs b/src/webserver/static_content.rs index 3acaad4c..6f66cb2c 100644 --- a/src/webserver/static_content.rs +++ b/src/webserver/static_content.rs @@ -49,3 +49,7 @@ pub fn css() -> Resource { pub fn icons() -> Resource { static_file_endpoint!("tabler-icons", "svg", "image/svg+xml") } + +pub fn favicon() -> Resource { + static_file_endpoint!("favicon", "svg", "image/svg+xml") +}