From 148a5352a3e81f38e9d56ad10ce59bcef8f6e9a4 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 18 Jan 2024 21:22:08 +0100 Subject: [PATCH] static stuff --- Cargo.lock | 137 +++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/build/mod.rs | 10 ++- src/build/statics.rs | 29 +++++++++ src/main.rs | 12 +++- src/utils.rs | 15 +++++ static/root/index.html | 18 ++++++ templates/slides.html | 17 +++++ 8 files changed, 237 insertions(+), 2 deletions(-) create mode 100644 src/build/statics.rs create mode 100644 static/root/index.html create mode 100644 templates/slides.html diff --git a/Cargo.lock b/Cargo.lock index af28c0e..b628ba5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,56 @@ dependencies = [ "memchr", ] +[[package]] +name = "askama" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b79091df18a97caea757e28cd2d5fda49c6cd4bd01ddffd7ff01ace0c0ad2c28" +dependencies = [ + "askama_derive", + "askama_escape", + "humansize", + "num-traits", + "percent-encoding", +] + +[[package]] +name = "askama_derive" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19fe8d6cb13c4714962c072ea496f3392015f0989b1a2847bb4b2d9effd71d83" +dependencies = [ + "askama_parser", + "basic-toml", + "mime", + "mime_guess", + "proc-macro2", + "quote", + "serde", + "syn", +] + +[[package]] +name = "askama_escape" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" + +[[package]] +name = "askama_parser" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acb1161c6b64d1c3d83108213c2a2533a342ac225aabd0bda218278c2ddb00c0" +dependencies = [ + "nom", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + [[package]] name = "backtrace" version = "0.3.69" @@ -41,6 +91,15 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "basic-toml" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2db21524cad41c5591204d22d75e1970a2d1f71060214ca931dc7d5afe2c14e5" +dependencies = [ + "serde", +] + [[package]] name = "cc" version = "1.0.83" @@ -117,6 +176,15 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +[[package]] +name = "humansize" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" +dependencies = [ + "libm", +] + [[package]] name = "indenter" version = "0.3.3" @@ -145,6 +213,12 @@ version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + [[package]] name = "log" version = "0.4.20" @@ -166,6 +240,28 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.1" @@ -175,6 +271,16 @@ dependencies = [ "adler", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -185,6 +291,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + [[package]] name = "object" version = "0.32.2" @@ -212,6 +327,12 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "pin-project-lite" version = "0.2.13" @@ -456,6 +577,15 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-ident" version = "1.0.12" @@ -468,10 +598,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "website" version = "0.1.0" dependencies = [ + "askama", "color-eyre", "fs_extra", "serde", diff --git a/Cargo.toml b/Cargo.toml index c0416d4..91be4f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +askama = "0.12.1" color-eyre = "0.6.2" fs_extra = "1.3.0" serde = { version = "1.0.195", features = ["derive"] } diff --git a/src/build/mod.rs b/src/build/mod.rs index 5d1382a..35ff436 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -2,6 +2,7 @@ mod blog; mod slides; +mod statics; use std::path::Path; @@ -9,7 +10,12 @@ use color_eyre::{eyre::Context, Result}; use crate::Config; -pub fn assemble_website(config: &Config, submodules: &Path, dist: &Path) -> Result<()> { +pub fn assemble_website( + config: &Config, + statics: &Path, + submodules: &Path, + dist: &Path, +) -> Result<()> { blog::build(&submodules.join("blog"), &dist.join("blog")).wrap_err("building blog")?; slides::build( &config.slides, @@ -18,6 +24,8 @@ pub fn assemble_website(config: &Config, submodules: &Path, dist: &Path) -> Resu ) .wrap_err("building slides")?; + statics::build(&config.slides, statics, dist).wrap_err("building root files")?; + add_cname(dist)?; Ok(()) diff --git a/src/build/statics.rs b/src/build/statics.rs new file mode 100644 index 0000000..f3f285f --- /dev/null +++ b/src/build/statics.rs @@ -0,0 +1,29 @@ +//! Root index.html and some other static stuff + +use std::{fs, path::Path}; + +use askama::Template; +use color_eyre::{eyre::WrapErr, Result}; + +use crate::{utils, SlidesConfig}; + +#[derive(askama::Template)] +#[template(path = "slides.html")] +struct Slides { + talks: Vec, +} + +pub fn build(config: &SlidesConfig, statics: &Path, dist: &Path) -> Result<()> { + utils::cp_content(&statics.join("root"), dist).wrap_err("copying root files")?; + + let slide_html = Slides { + talks: config.talks.clone(), + } + .render() + .wrap_err("rendering slide index")?; + + fs::write(dist.join("slides").join("index.html"), slide_html) + .wrap_err("writing slides index.html")?; + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index d84e4d3..19aecc6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,6 +33,16 @@ fn main() -> Result<()> { // Set the current dir to nonsense to fail everything that relies on it let _ = std::env::set_current_dir("/"); + if std::env::args().nth(1).as_deref() == Some("clean") { + info!("Cleaning dist"); + match std::fs::remove_dir_all(root.join("dist")) { + Ok(()) => {} + Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} + e => return e.wrap_err("removing dist"), + } + return Ok(()); + } + let config = std::fs::read_to_string(root.join("config.toml")).wrap_err("reading config.toml")?; let config = toml::from_str::(&config).wrap_err("parsing config.toml")?; @@ -45,7 +55,7 @@ fn main() -> Result<()> { submodule::sync(&submodules_path, &sub_config).wrap_err("syncing subtrees")?; let dist_path = root.join("dist"); - build::assemble_website(&config, &submodules_path, &dist_path)?; + build::assemble_website(&config, &root.join("static"), &submodules_path, &dist_path)?; Ok(()) } diff --git a/src/utils.rs b/src/utils.rs index 3dad672..33c4ac4 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -53,3 +53,18 @@ pub fn cp_r(from: &Path, to: &Path) -> Result<()> { .wrap_err(format!("copying to {}", to.display()))?; Ok(()) } + +pub fn cp_content(from: &Path, to: &Path) -> Result<()> { + fs_extra::dir::copy( + from, + to, + &CopyOptions { + overwrite: true, + copy_inside: true, + content_only: true, + ..CopyOptions::default() + }, + ) + .wrap_err(format!("copying to {}", to.display()))?; + Ok(()) +} diff --git a/static/root/index.html b/static/root/index.html new file mode 100644 index 0000000..ad44eb3 --- /dev/null +++ b/static/root/index.html @@ -0,0 +1,18 @@ + + + + + + nilstrieb.dev + + +

hi!

+

This is my website. It is work in progress.

+

my blog

+

I have a blog, it might be interesting, maybe.

+ blog +

slides

+

i have given one talk, here are its slides, isnt this amazing

+ slides from talks + + \ No newline at end of file diff --git a/templates/slides.html b/templates/slides.html new file mode 100644 index 0000000..c8d7624 --- /dev/null +++ b/templates/slides.html @@ -0,0 +1,17 @@ + + + + + + Slides + + +

Slides

+

Talks I have given with slides available:

+
+ {% for talk in talks %} + {{ talk }} + {% endfor %} +
+ + \ No newline at end of file