Getting ready for 1.2 & new site release

- improved support for serving static resources from the binary, now supporting images
- added new logo
- changed save button
- fixed footer attribution text, it is not true anymore that MicroBin is made by myself
- replaced footer GitHub link with microbin.eu link
This commit is contained in:
Daniel Szabo 2022-11-01 20:56:07 +02:00
parent 44b55ae08e
commit 2198cbdff9
13 changed files with 149 additions and 68 deletions

47
Cargo.lock generated
View file

@ -1293,8 +1293,10 @@ dependencies = [
"lazy_static",
"linkify",
"log",
"mime_guess",
"qrcode-generator",
"rand",
"rust-embed",
"sanitize-filename",
"serde",
"serde_json",
@ -1702,6 +1704,40 @@ version = "0.6.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
[[package]]
name = "rust-embed"
version = "6.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "283ffe2f866869428c92e0d61c2f35dfb4355293cdfdc48f49e895c15f1333d1"
dependencies = [
"rust-embed-impl",
"rust-embed-utils",
"walkdir",
]
[[package]]
name = "rust-embed-impl"
version = "6.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31ab23d42d71fb9be1b643fe6765d292c5e14d46912d13f3ae2815ca048ea04d"
dependencies = [
"proc-macro2",
"quote",
"rust-embed-utils",
"syn",
"walkdir",
]
[[package]]
name = "rust-embed-utils"
version = "7.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1669d81dfabd1b5f8e2856b8bbe146c6192b0ba22162edc738ac0a5de18f054"
dependencies = [
"sha2",
"walkdir",
]
[[package]]
name = "rustc_version"
version = "0.4.0"
@ -1820,6 +1856,17 @@ dependencies = [
"digest",
]
[[package]]
name = "sha2"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.0"

View file

@ -32,6 +32,8 @@ actix-web-httpauth = "0.6.0"
lazy_static = "1.4.0"
syntect = "5.0"
qrcode-generator = "4.1.6"
rust-embed = "6.4.2"
mime_guess = "2.0.4"
[profile.release]
lto = true

View file

@ -18,7 +18,7 @@ Or install from Cargo:
And run with your custom configuration:
`microbin --port 8080 --highlightsyntax --editable`
`microbin --port 8080 --public-path https://myserver.net --highlightsyntax --editable`
### Features
- Is very small

View file

@ -33,7 +33,7 @@ pub async fn info(data: web::Data<AppState>) -> HttpResponse {
args: &ARGS,
pastas: &pastas,
status: &String::from(status),
version_string: &String::from("1.2.0-20221029"),
version_string: &String::from("1.2.0-20221101"),
message: &String::from(message),
}
.render()

View file

@ -1,36 +1,63 @@
use actix_web::{get, web, HttpResponse};
use askama::Template;
use std::marker::PhantomData;
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
use mime_guess::from_path;
use rust_embed::RustEmbed;
#[derive(Template)]
#[template(path = "water.css", escape = "none")]
struct WaterCSS<'a> {
_marker: PhantomData<&'a ()>,
}
#[derive(RustEmbed)]
#[folder = "templates/assets/"]
struct Asset;
#[derive(Template)]
#[template(path = "favicon.svg", escape = "none")]
struct Favicon<'a> {
_marker: PhantomData<&'a ()>,
}
#[get("/static/{resource}")]
pub async fn static_resources(resource_id: web::Path<String>) -> HttpResponse {
match resource_id.into_inner().as_str() {
"water.css" => HttpResponse::Ok().content_type("text/css").body(
WaterCSS {
_marker: Default::default(),
}
.render()
.unwrap(),
),
"favicon.svg" => HttpResponse::Ok().content_type("image/svg+xml").body(
Favicon {
_marker: Default::default(),
}
.render()
.unwrap(),
),
_ => HttpResponse::NotFound().content_type("text/html").finish(),
fn handle_embedded_file(path: &str) -> HttpResponse {
match Asset::get(path) {
Some(content) => HttpResponse::Ok()
.content_type(from_path(path).first_or_octet_stream().as_ref())
.body(content.data.into_owned()),
None => HttpResponse::NotFound().body("404 Not Found"),
}
}
#[actix_web::get("/static/{_:.*}")]
async fn static_resources(path: web::Path<String>) -> impl Responder {
handle_embedded_file(path.as_str())
}
// #[derive(Template)]
// #[template(path = "water.css", escape = "none")]
// struct WaterCSS<'a> {
// _marker: PhantomData<&'a ()>,
// }
// // #[derive(Template)]
// // #[template(path = "logo.png", escape = "none")]
// struct LogoPNG<'a> {
// _marker: PhantomData<&'a ()>,
// }
// #[derive(Template)]
// #[template(path = "favicon.svg", escape = "none")]
// struct Favicon<'a> {
// _marker: PhantomData<&'a ()>,
// }
// #[get("/static/{resource}")]
// pub async fn static_resources(resource_id: web::Path<String>) -> HttpResponse {
// match resource_id.into_inner().as_str() {
// "water.css" => HttpResponse::Ok().content_type("text/css").body(
// WaterCSS {
// _marker: Default::default(),
// }
// .render()
// .unwrap(),
// ),
// "logo.png" => HttpResponse::Ok()
// .content_type("image/png")
// .body(Ok(EmbedFile::open("templates/logo.png")?)),
// "favicon.svg" => HttpResponse::Ok().content_type("image/svg+xml").body(
// Favicon {
// _marker: Default::default(),
// }
// .render()
// .unwrap(),
// ),
// _ => HttpResponse::NotFound().content_type("text/html").finish(),
// }
// }

View file

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

BIN
templates/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View file

@ -1,10 +1,9 @@
{% if !args.hide_footer %}
<hr>
<p style="font-size: smaller">
{% if args.footer_text.as_ref().is_none() %}
MicroBin by Dániel Szabó. Fork me on <a href="https://github.com/szabodanika/microbin">GitHub</a>!
<a href="https://microbin.eu">MicroBin</a> by Dániel Szabó and the FOSS Community.
Let's keep the Web <b>compact</b>, <b>accessible</b> and <b>humane</b>!
{%- else %}
{{ args.footer_text.as_ref().unwrap() }}
@ -14,4 +13,5 @@
{%- endif %}
</body>
</html>

View file

@ -10,7 +10,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
<link rel="icon" type="image/svg+xml" href="{{ args.public_path }}/static/favicon.svg">
{% if !args.pure_html %}
{% if args.custom_css.as_ref().is_none() %}
<link rel="stylesheet" href="{{ args.public_path }}/static/water.css">
@ -48,20 +48,17 @@
<b style="margin-right: 0.5rem">
{% if !args.hide_logo %}
<i><span style="font-size:2.2rem; margin-right:1rem">μ</span></i>
{%- endif %}
{% if args.title.as_ref().is_none() %}
MicroBin
{%- else %}
{{ args.title.as_ref().unwrap() }}
{%- endif %}
<!-- <i><span style="font-size:2.2rem; margin-right:1rem">μ</span></i> -->
<img width=26 style="margin-bottom: -6px; margin-right: 0.5rem;"
src="{{ args.public_path }}/static/logo.png">
{%- endif %} {% if args.title.as_ref().is_none() %}
MicroBin {%- else %} {{ args.title.as_ref().unwrap() }} {%- endif %}
</b>
<a href="{{ args.public_path }}/" style="margin-right: 0.5rem; margin-left: 0.5rem">New
Pasta</a>
</a>
<a href="{{ args.public_path }}/pastalist" style="margin-right: 0.5rem; margin-left: 0.5rem">Pasta List</a>
<a href="{{ args.public_path }}/pastalist" style="margin-right: 0.5rem; margin-left: 0.5rem">List</a>
<a href="{{ args.public_path }}/info" style="margin-right: 0.5rem; margin-left: 0.5rem">Info</a>

View file

@ -164,23 +164,27 @@
</div>
<label>Content</label>
<br>
<textarea style="width: 100%; min-height: 100px" name="content" autofocus></textarea>
<textarea style="width: 100%; min-height: 100px; margin-bottom: 2em" name="content" autofocus></textarea>
<div style="overflow:auto;">
{% if !args.no_file_upload %}
<div>
<label for="file" id="attach-file-button-label"><a role="button" id="attach-file-button">Attach File</a></label>
<div style="float: left">
<label for="file" id="attach-file-button-label"><a role="button" id="attach-file-button">Attach
File</a></label>
<br>
<input type="file" id="file" name="file" />
</div>
{% endif %}
{% if args.readonly %}
<input style="width: 140px; background-color: limegreen" disabled type="submit" value="Read Only" />
<b>
<input style="width: 140px; float: right; background-color: #0076d18f;" disabled type="submit"
value="Read Only" /></b>
{%- else %}
<input style="width: 140px; background-color: limegreen" type="submit" value="Save" />
<b>
<input style="width: 140px; float: right; background-color: #0076d18f;" type="submit" value="Save" />
</b>
{%- endif %}
</td>
</div>
<br>
</form>
<script>
@ -199,7 +203,7 @@
#settings {
display: grid;
grid-gap: 4px;
grid-gap: 6px;
grid-template-columns: repeat(auto-fit, 150px);
grid-template-rows: repeat(1, 90px);
margin-bottom: 0.5rem;

View file

@ -4,13 +4,13 @@
<div style="height: 200px;">
<div style="float: left">
<h4>Links</h4>
<a href="https://docs.microbin.eu" style="margin-right: 1rem">Documentation and Help</a>
<a href="https://microbin.eu/documentation" style="margin-right: 1rem">Documentation and Help</a>
<br>
<a href="https://github.com/szabodanika/microbin" style="margin-right: 1rem">Source Code</a>
<br>
<a href="https://github.com/szabodanika/microbin/issues" style="margin-right: 1rem">Feedback</a>
<br>
<a href="microbin.eu/sponsor">Sponsor</a>
<a href="https://microbin.eu/donate">Donate and Sponsor</a>
</div>
<div style="float: right">

View file

@ -45,7 +45,12 @@
</div>
{%- endif %}
<div>
{% if pasta.read_count == 1 %}
<p style="font-size: small">Read {{pasta.read_count}} time, last {{pasta.last_read_time_ago_as_string()}}</p>
{%- else %}
<p style="font-size: small">Read {{pasta.read_count}} times, last {{pasta.last_read_time_ago_as_string()}}</p>
{%- endif %}
</div>
<br>
@ -86,7 +91,6 @@
code-line::before {
content: counter(listing);
display: inline-block;
float: left;
padding-left: auto;
margin-left: auto;
text-align: left;