inline svg icons in the SQLPage binary
icons are now loaded directly from the sqlpage binary instead of loading them from a CDN This makes it possible to host a SQLPage website on an intranet without access to the internet. Fixes https://github.com/lovasoa/SQLpage/issues/37
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/* !include https://cdn.jsdelivr.net/npm/@tabler/icons@2.30.0/tabler-sprite.svg */
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
{{#if icon}}
|
||||
<div class="icon alert-icon">
|
||||
<i class="ti ti-{{icon}}"></i>
|
||||
{{~icon_img icon~}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
{{/if}}
|
||||
{{#if icon}}
|
||||
<div class="ribbon bg-{{color}} fs-2">
|
||||
<i class="ti ti-{{icon}}"></i>
|
||||
{{~icon_img icon~}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</{{#if link}}a {{else}}div{{/if}}>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
"
|
||||
download="{{default filename title}}.csv"
|
||||
class="btn btn-{{default color "primary"}}">
|
||||
<i class="icon ti ti-{{default icon "download"}}"></i>
|
||||
{{~icon_img (default icon "download")~}}
|
||||
{{default title "Download"}}
|
||||
</a>
|
||||
</div>
|
||||
@@ -15,7 +15,7 @@
|
||||
<span class="status status-{{color}} {{#if active}}fw-bold{{/if}}">
|
||||
{{/if}}
|
||||
{{#if icon}}
|
||||
<i class="icon ti ti-{{icon}}"></i>
|
||||
{{~icon_img icon~}}
|
||||
{{/if}}
|
||||
{{#if description}}
|
||||
{{description}}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<div class="card-body text-center p-4 p-lg-5 pt-0 pt-lg-0">
|
||||
{{#if icon}}
|
||||
<div style="margin-top: -1.5rem;" class="badge bg-{{default color 'success'}} fs-1 mb-4 p-2">
|
||||
<i class="ti ti-{{icon}}"></i>
|
||||
{{~icon_img icon 30~}}
|
||||
</div>
|
||||
{{/if}}
|
||||
<h2>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
{{/if}}
|
||||
{{#if icon}}
|
||||
<div class="col-auto fs-2">
|
||||
<i class="ti ti-{{icon}}"></i>
|
||||
{{~icon_img icon~}}
|
||||
</div>
|
||||
{{/if}}
|
||||
<div class="col text-truncate">
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
<title>{{default title "SQLPage"}}</title>
|
||||
|
||||
<link rel="stylesheet" href="/{{static_path 'sqlpage.css'}}">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@2.19.0/tabler-icons.min.css"
|
||||
integrity="sha384-a8pgu0eDAmHMVlQuzUEoHyapgzLXfOaTTNrMzPivsvAts7LkllyAYpRE4saDWQj7" crossorigin="anonymous">
|
||||
|
||||
{{#each (to_array css)}}
|
||||
{{#if this}}
|
||||
<link rel="stylesheet" href="{{this}}">
|
||||
@@ -51,7 +48,7 @@
|
||||
class="navbar-brand-image">
|
||||
{{/if}}
|
||||
{{#if icon}}
|
||||
<i class="icon ti ti-{{icon}}"></i>
|
||||
{{~icon_img icon~}}
|
||||
{{/if}}
|
||||
{{title}}
|
||||
</a>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
{{#if description}}data-bs-toggle="tooltip" title="{{description}}"{{/if}}
|
||||
>
|
||||
{{#if icon}}
|
||||
<i class="ti ti-{{icon}}"></i>
|
||||
{{~icon_img icon~}}
|
||||
{{/if}}
|
||||
{{title}}
|
||||
{{#if link}}</a>{{else}}</span>{{/if}}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
{{{markdown this}}}
|
||||
{{~else~}}
|
||||
{{~#if (array_contains ../../icon @key)~}}
|
||||
<i class="ti ti-{{this}}"></i>
|
||||
{{~icon_img icon~}}
|
||||
{{~else~}}
|
||||
{{this}}
|
||||
{{~/if~}}
|
||||
|
||||
@@ -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,
|
||||
"<svg width={size} height={size}><use href=\"/{}#tabler-{name}\" /></svg>",
|
||||
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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user