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", "lazy_static",
"linkify", "linkify",
"log", "log",
"mime_guess",
"qrcode-generator", "qrcode-generator",
"rand", "rand",
"rust-embed",
"sanitize-filename", "sanitize-filename",
"serde", "serde",
"serde_json", "serde_json",
@ -1702,6 +1704,40 @@ version = "0.6.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" 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]] [[package]]
name = "rustc_version" name = "rustc_version"
version = "0.4.0" version = "0.4.0"
@ -1820,6 +1856,17 @@ dependencies = [
"digest", "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]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.4.0" version = "1.4.0"

View file

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

View file

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

View file

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

View file

@ -1,36 +1,63 @@
use actix_web::{get, web, HttpResponse}; use actix_web::{web, App, HttpResponse, HttpServer, Responder};
use askama::Template; use mime_guess::from_path;
use std::marker::PhantomData; use rust_embed::RustEmbed;
#[derive(Template)] #[derive(RustEmbed)]
#[template(path = "water.css", escape = "none")] #[folder = "templates/assets/"]
struct WaterCSS<'a> { struct Asset;
_marker: PhantomData<&'a ()>,
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"),
}
} }
#[derive(Template)] #[actix_web::get("/static/{_:.*}")]
#[template(path = "favicon.svg", escape = "none")] async fn static_resources(path: web::Path<String>) -> impl Responder {
struct Favicon<'a> { handle_embedded_file(path.as_str())
_marker: PhantomData<&'a ()>,
} }
#[get("/static/{resource}")] // #[derive(Template)]
pub async fn static_resources(resource_id: web::Path<String>) -> HttpResponse { // #[template(path = "water.css", escape = "none")]
match resource_id.into_inner().as_str() { // struct WaterCSS<'a> {
"water.css" => HttpResponse::Ok().content_type("text/css").body( // _marker: PhantomData<&'a ()>,
WaterCSS { // }
_marker: Default::default(),
} // // #[derive(Template)]
.render() // // #[template(path = "logo.png", escape = "none")]
.unwrap(), // struct LogoPNG<'a> {
), // _marker: PhantomData<&'a ()>,
"favicon.svg" => HttpResponse::Ok().content_type("image/svg+xml").body( // }
Favicon {
_marker: Default::default(), // #[derive(Template)]
} // #[template(path = "favicon.svg", escape = "none")]
.render() // struct Favicon<'a> {
.unwrap(), // _marker: PhantomData<&'a ()>,
), // }
_ => HttpResponse::NotFound().content_type("text/html").finish(),
} // #[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 %} {% if !args.hide_footer %}
<hr> <hr>
<p style="font-size: smaller"> <p style="font-size: smaller">
{% if args.footer_text.as_ref().is_none() %} {% 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>! Let's keep the Web <b>compact</b>, <b>accessible</b> and <b>humane</b>!
{%- else %} {%- else %}
{{ args.footer_text.as_ref().unwrap() }} {{ args.footer_text.as_ref().unwrap() }}
@ -14,4 +13,5 @@
{%- endif %} {%- endif %}
</body> </body>
</html> </html>

View file

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

View file

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

View file

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

View file

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