mirror of
https://github.com/RGBCube/rgbcube.github.io
synced 2025-05-14 05:54:58 +00:00
Clean up minify functions
This commit is contained in:
parent
9336ad99b0
commit
80c8f36435
5 changed files with 26 additions and 17 deletions
|
@ -1,20 +1,26 @@
|
|||
use embed_file::embed_string as embed;
|
||||
use maud::{
|
||||
html,
|
||||
Markup,
|
||||
};
|
||||
|
||||
use crate::page;
|
||||
use crate::{
|
||||
minify,
|
||||
page,
|
||||
};
|
||||
|
||||
const FACES: [&str; 6] = ["front", "top", "back", "bottom", "right", "left"];
|
||||
|
||||
pub fn create(styling: &str, faces: [Markup; 6]) -> Markup {
|
||||
pub fn create<S: AsRef<str>>(styling: S, faces: [Markup; 6]) -> Markup {
|
||||
page::create(
|
||||
html! {
|
||||
link href="cube.min.css" rel="stylesheet";
|
||||
style {
|
||||
(minify::css(embed!("cube.css")))
|
||||
}
|
||||
},
|
||||
html! {
|
||||
style {
|
||||
(styling)
|
||||
(styling.as_ref())
|
||||
}
|
||||
|
||||
div class="scene" {
|
||||
|
@ -27,7 +33,9 @@ pub fn create(styling: &str, faces: [Markup; 6]) -> Markup {
|
|||
}
|
||||
}
|
||||
|
||||
script src="cube.min.js" {}
|
||||
script {
|
||||
(minify::js(embed!("cube.js")))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
const SPECIAL_CHARS: [char; 8] = ['{', '}', ':', ';', ' ', '\n', '!', '>'];
|
||||
|
||||
// Taken from https://github.com/amgarrett09/rust-css-minifier/blob/master/src/minify/mod.rs.
|
||||
pub fn css(input: &str) -> String {
|
||||
pub fn css<S: AsRef<str>>(input: S) -> String {
|
||||
let mut last_char: Vec<char> = " ".chars().collect();
|
||||
let mut output = Vec::new();
|
||||
|
||||
let mut inside_comment = false;
|
||||
|
||||
for c in input.chars() {
|
||||
for c in input.as_ref().chars() {
|
||||
// We're in a comment if we find '/*'
|
||||
if !inside_comment && c == '*' && last_char[0] == '/' {
|
||||
inside_comment = true;
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
use anyhow::Context;
|
||||
use minify_js::{
|
||||
Session,
|
||||
TopLevelMode,
|
||||
};
|
||||
|
||||
pub fn js(input: &str) -> String {
|
||||
pub fn js<S: AsRef<str>>(input: S) -> String {
|
||||
let session = Session::new();
|
||||
let mut out = Vec::new();
|
||||
|
||||
minify_js::minify(&session, TopLevelMode::Module, input.as_bytes(), &mut out)
|
||||
.with_context(|| format!("Failed to minify::js: {code}."))
|
||||
.unwrap();
|
||||
minify_js::minify(
|
||||
&session,
|
||||
TopLevelMode::Module,
|
||||
input.as_ref().as_bytes(),
|
||||
&mut out,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
String::from_utf8(out)
|
||||
.with_context(|| format!("Failed to create a string from minify::js output: {out:?}."))
|
||||
.unwrap()
|
||||
String::from_utf8(out).unwrap()
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ use crate::{
|
|||
|
||||
pub async fn generate() -> Markup {
|
||||
cube::create(
|
||||
minify::css(embed!("404.css").as_ref()).as_str(),
|
||||
minify::css(embed!("404.css")),
|
||||
array::from_fn(|_| {
|
||||
(html! {
|
||||
div class="frame" {}
|
||||
|
|
|
@ -11,7 +11,7 @@ use crate::{
|
|||
|
||||
pub async fn generate() -> Markup {
|
||||
cube::create(
|
||||
minify::css(embed!("index.css").as_ref()).as_str(),
|
||||
minify::css(embed!("index.css")),
|
||||
[
|
||||
html! {
|
||||
a href="contact" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue