diff --git a/CHANGELOG.md b/CHANGELOG.md index 34b68ff3..46c8b653 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # CHANGELOG.md +## unreleased + + - Icons are now loaded directly from the sqlpage binary instead of loading them from a CDN. + This allows pages to load faster, and to get a better score on google's performance audits, potentially improving your position in search results. + - This also makes it possible to host a SQLPage website on an intranet without access to the internet. + - Fixes https://github.com/lovasoa/SQLpage/issues/37 + ## 0.9.2 (2023-08-01) - Added support for more SQL data types. This notably fixes an issue with the display of datetime columns in tables. diff --git a/sqlpage/tabler-icons.svg b/sqlpage/tabler-icons.svg new file mode 100644 index 00000000..11756433 --- /dev/null +++ b/sqlpage/tabler-icons.svg @@ -0,0 +1 @@ +/* !include https://cdn.jsdelivr.net/npm/@tabler/icons@2.30.0/tabler-sprite.svg */ \ No newline at end of file diff --git a/sqlpage/templates/alert.handlebars b/sqlpage/templates/alert.handlebars index 42c0cf38..3c8802e6 100644 --- a/sqlpage/templates/alert.handlebars +++ b/sqlpage/templates/alert.handlebars @@ -8,7 +8,7 @@ {{#if icon}}
- + {{~icon_img icon~}}
{{/if}} diff --git a/sqlpage/templates/card.handlebars b/sqlpage/templates/card.handlebars index 67174e4b..7983ae78 100644 --- a/sqlpage/templates/card.handlebars +++ b/sqlpage/templates/card.handlebars @@ -45,7 +45,7 @@ {{/if}} {{#if icon}}
- + {{~icon_img icon~}}
{{/if}} diff --git a/sqlpage/templates/csv.handlebars b/sqlpage/templates/csv.handlebars index b813946c..8d2280fd 100644 --- a/sqlpage/templates/csv.handlebars +++ b/sqlpage/templates/csv.handlebars @@ -18,7 +18,7 @@ " download="{{default filename title}}.csv" class="btn btn-{{default color "primary"}}"> - + {{~icon_img (default icon "download")~}} {{default title "Download"}} \ No newline at end of file diff --git a/sqlpage/templates/datagrid.handlebars b/sqlpage/templates/datagrid.handlebars index 0ab70bb0..bd881eb5 100644 --- a/sqlpage/templates/datagrid.handlebars +++ b/sqlpage/templates/datagrid.handlebars @@ -15,7 +15,7 @@ {{/if}} {{#if icon}} - + {{~icon_img icon~}} {{/if}} {{#if description}} {{description}} diff --git a/sqlpage/templates/hero.handlebars b/sqlpage/templates/hero.handlebars index 5b68f7f2..7a9d1466 100644 --- a/sqlpage/templates/hero.handlebars +++ b/sqlpage/templates/hero.handlebars @@ -28,7 +28,7 @@
{{#if icon}}
- + {{~icon_img icon 30~}}
{{/if}}

diff --git a/sqlpage/templates/list.handlebars b/sqlpage/templates/list.handlebars index a9c0d87f..fc51a0f5 100644 --- a/sqlpage/templates/list.handlebars +++ b/sqlpage/templates/list.handlebars @@ -14,7 +14,7 @@ {{/if}} {{#if icon}}
- + {{~icon_img icon~}}
{{/if}}
diff --git a/sqlpage/templates/shell.handlebars b/sqlpage/templates/shell.handlebars index d9fd369d..01b81790 100644 --- a/sqlpage/templates/shell.handlebars +++ b/sqlpage/templates/shell.handlebars @@ -5,9 +5,6 @@ {{default title "SQLPage"}} - - {{#each (to_array css)}} {{#if this}} @@ -51,7 +48,7 @@ class="navbar-brand-image"> {{/if}} {{#if icon}} - + {{~icon_img icon~}} {{/if}} {{title}} diff --git a/sqlpage/templates/steps.handlebars b/sqlpage/templates/steps.handlebars index ca540856..9d01671e 100644 --- a/sqlpage/templates/steps.handlebars +++ b/sqlpage/templates/steps.handlebars @@ -15,7 +15,7 @@ {{#if description}}data-bs-toggle="tooltip" title="{{description}}"{{/if}} > {{#if icon}} - + {{~icon_img icon~}} {{/if}} {{title}} {{#if link}}{{else}}{{/if}} diff --git a/sqlpage/templates/table.handlebars b/sqlpage/templates/table.handlebars index 0817a600..56fe0a45 100644 --- a/sqlpage/templates/table.handlebars +++ b/sqlpage/templates/table.handlebars @@ -35,7 +35,7 @@ {{{markdown this}}} {{~else~}} {{~#if (array_contains ../../icon @key)~}} - + {{~icon_img icon~}} {{~else~}} {{this}} {{~/if~}} diff --git a/src/templates.rs b/src/templates.rs index aaf07d69..744e4874 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -153,6 +153,31 @@ fn sum_helper<'reg, 'rc>( Ok(()) } +fn icon_img_helper<'reg, 'rc>( + helper: &handlebars::Helper<'rc>, + _r: &'reg Handlebars<'reg>, + _ctx: &'rc Context, + _rc: &mut handlebars::RenderContext<'reg, 'rc>, + writer: &mut dyn handlebars::Output, +) -> handlebars::HelperResult { + let name = helper + .params() + .get(0) + .and_then(|v| v.value().as_str()) + .ok_or(RenderErrorReason::InvalidParamType("str"))?; + let size = helper + .params() + .get(1) + .and_then(|v| v.value().as_u64()) + .unwrap_or(24); + write!( + writer, + "", + static_filename!("tabler-icons.svg") + )?; + Ok(()) +} + const STATIC_TEMPLATES: Dir = include_dir!("$CARGO_MANIFEST_DIR/sqlpage/templates"); impl AllTemplates { @@ -231,6 +256,9 @@ impl AllTemplates { }); handlebars.register_helper("static_path", Box::new(static_path)); + // icon helper: generate an image with the specified icon + handlebars.register_helper("icon_img", Box::new(icon_img_helper)); + handlebars_helper!(markdown_helper: |x: str| markdown::to_html_with_options(x, &markdown::Options::gfm()) .unwrap_or_else(|s|s) diff --git a/src/webserver/http.rs b/src/webserver/http.rs index 94540f59..69f99324 100644 --- a/src/webserver/http.rs +++ b/src/webserver/http.rs @@ -512,6 +512,7 @@ pub fn create_app( App::new() .service(static_content::js()) .service(static_content::css()) + .service(static_content::icons()) .default_service(fn_service(main_handler)) .wrap(Logger::default()) .wrap( diff --git a/src/webserver/static_content.rs b/src/webserver/static_content.rs index df6b1cb7..5529fe62 100644 --- a/src/webserver/static_content.rs +++ b/src/webserver/static_content.rs @@ -34,3 +34,7 @@ pub fn js() -> Resource { pub fn css() -> Resource { static_file_endpoint!("sqlpage", "css", "text/css") } + +pub fn icons() -> Resource { + static_file_endpoint!("tabler-icons", "svg", "image/svg+xml") +}