Embed Xess directly

Nobody can stop me now.
This commit is contained in:
Gabriel Simmer 2022-12-12 14:59:35 +00:00
parent ee842aa5de
commit a41e523097
Signed by: arch
GPG key ID: C81B106D46C5B875
3 changed files with 146 additions and 8 deletions

View file

@ -32,6 +32,24 @@
pkgs.libiconv pkgs.libiconv
]; ];
}; };
dockerImage = pkgs.dockerTools.buildImage {
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [
pkgs.coreutils
pkgs.bash
];
pathsToLink = [ "/bin" ];
};
name = "dref";
config = {
Cmd = [ "${my-crate}/bin/docker-rs-dashboard" ];
ExposedPorts = {
"3000/tcp" = {};
};
};
};
in in
{ {
checks = { checks = {
@ -43,11 +61,11 @@
}; };
packages = rec { packages = rec {
xess = Xess.packages.${system}.customized ./static/css/theme.css;
bin = my-crate; bin = my-crate;
docker = dockerImage;
default = pkgs.symlinkJoin { default = pkgs.symlinkJoin {
name = "dref-${bin.version}"; name = "dref-${bin.version}";
paths = [ bin xess ]; paths = [ bin ];
}; };
}; };

113
src/css.rs Normal file
View file

@ -0,0 +1,113 @@
use std::{error::Error, path::Path, fs};
const XESS: &str = r#"
:root {
--background-color: 236;
--text-color: 55;
--accent-color: 200;
--width: 80ch;
--padding: 0;
--selection: hsla(var(--accent-color), 80%, 30%, 100%);
--selection-light: hsla(var(--accent-color), 50%, 80%, 100%);
--background: hsla(var(--background-color), 100%, 10%, 100%);
--background-light: hsla(var(--background-color), 10%, 95%, 100%);
--text: hsla(var(--text-color), 0%, 90%, 100%);
--text-light: hsla(var(--text-color), 90%, 5%, 100%);
--pre-background: hsla(var(--background-color), 90%, 5%, 100%);
--pre-background-light: hsla(var(--background-color), 10%, 80%, 100%);
--a-background: hsla(var(--background-color), 90%, 5%, 100%);
--a-background-light: hsla(var(--background-color), 30%, 90%, 100%);
--a-color: hsla(var(--accent-color), 70%, 85%, 100%);
--a-color-light: hsla(var(--accent-color), 80%, 10%, 100%);
--blockquote-border: 0.5ch solid hsla(var(--accent-color), 80%, 80%, 100%);
--blockquote-border-light: 0.5ch solid hsla(var(--accent-color), 50%, 30%, 100%);
}
main {
font-family: monospace, monospace;
max-width: var(--width);
padding: var(--padding);
margin: auto;
}
@media only screen and (max-device-width: 736px) {
main {
padding: 0rem;
}
}
::selection {
background: var(--selection);
}
body {
background: var(--background);
color: var(--text);
}
pre {
background-color: var(--pre-background);
padding: 1em;
border: 0;
}
a, a:active, a:visited {
color: var(--selection);
background-color: var(--a-background);
}
h1, h2, h3, h4, h5 {
margin-bottom: .1rem;
}
blockquote {
border-left: var(--blockquote-border);
margin: 0.5em 10px;
padding: 0.5em 10px;
}
footer {
align: center;
}
@media (prefers-color-scheme: light) {
::selection {
background: var(--selection-light);
}
body {
background: var(--background-light);
color: var(--text-light);
}
pre {
background-color: var(--pre-background-light);
padding: 1em;
border: 0;
}
a, a:active, a:visited {
color: var(--a-color-light);
background-color: var(--a-background-light);
}
h1, h2, h3, h4, h5 {
margin-bottom: .1rem;
}
blockquote {
border-left: var(--blockquote-border-light);
margin: 0.5em 10px;
padding: 0.5em 10px;
}
}
"#;
pub fn render_css() -> Result<String, Box<dyn Error>> {
if Path::new("theme.css").exists() {
let theme: String = fs::read_to_string("theme.css")?.parse()?;
return Ok(format!("{}\n{}", XESS, theme))
}
Ok(XESS.to_string())
}

View file

@ -1,9 +1,10 @@
use std::{boxed, error, fs}; mod css;
use std::{boxed, error};
use dkregistry::v2::Client; use dkregistry::v2::Client;
use maud::{html, Markup, DOCTYPE}; use maud::{html, Markup, DOCTYPE};
use axum::{Router, routing::get}; use axum::{Router, routing::get, response::IntoResponse};
use futures::{stream::StreamExt, future::join_all}; use futures::{stream::StreamExt, future::join_all};
use axum_extra::routing::SpaRouter;
// To be expanded upon. // To be expanded upon.
#[derive(Debug)] #[derive(Debug)]
@ -20,8 +21,7 @@ struct Tag {
async fn main() { async fn main() {
// build our application with a single route // build our application with a single route
let app = Router::new() let app = Router::new()
.route("/", get(root)) .route("/", get(root)).route("/styles.css", get(css));
.merge(SpaRouter::new("/static", "result/static"));
// run it with hyper on localhost:3000 // run it with hyper on localhost:3000
println!("Running webserver on port :3000"); println!("Running webserver on port :3000");
@ -31,12 +31,19 @@ async fn main() {
.unwrap(); .unwrap();
} }
async fn css() -> impl IntoResponse {
([("Content-Type", "text/css")], match css::render_css() {
Ok(css) => css,
Err(_) => "".to_owned(),
})
}
fn header(page_title: &str) -> Markup { fn header(page_title: &str) -> Markup {
html! { html! {
(DOCTYPE) (DOCTYPE)
meta charset="utf-8"; meta charset="utf-8";
title { (page_title) } title { (page_title) }
link rel="stylesheet" href="/static/css/xess.css"; link rel="stylesheet" href="/styles.css";
} }
} }