diff --git a/Cargo.lock b/Cargo.lock index d7d6fb4..a2a8d9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -212,6 +212,17 @@ dependencies = [ "libc", ] +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.28.1" @@ -458,6 +469,12 @@ version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "proc-macro2" version = "1.0.76" @@ -476,6 +493,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "redox_syscall" version = "0.4.1" @@ -765,6 +812,7 @@ dependencies = [ "color-eyre", "fs_extra", "notify", + "rand", "serde", "serde_derive", "toml", diff --git a/Cargo.toml b/Cargo.toml index ba3e442..493fdb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ askama = "0.12.1" color-eyre = "0.6.2" fs_extra = "1.3.0" notify = "6.1.1" +rand = "0.8.5" serde = { version = "1.0.195", features = ["derive"] } serde_derive = "1.0.195" toml = "0.8.8" diff --git a/src/build/mod.rs b/src/build/mod.rs index 35ff436..dfa65b3 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -11,6 +11,7 @@ use color_eyre::{eyre::Context, Result}; use crate::Config; pub fn assemble_website( + rng: &mut rand::rngs::StdRng, config: &Config, statics: &Path, submodules: &Path, @@ -24,7 +25,7 @@ pub fn assemble_website( ) .wrap_err("building slides")?; - statics::build(&config.slides, statics, dist).wrap_err("building root files")?; + statics::build(rng, &config.slides, statics, dist).wrap_err("building root files")?; add_cname(dist)?; diff --git a/src/build/statics.rs b/src/build/statics.rs index b85badd..4b98e4f 100644 --- a/src/build/statics.rs +++ b/src/build/statics.rs @@ -4,6 +4,7 @@ use std::{fs, path::Path}; use askama::Template; use color_eyre::{eyre::WrapErr, Result}; +use rand::seq::SliceRandom; use crate::{utils, SlidesConfig, Talk}; @@ -13,9 +14,33 @@ struct Slides { talks: Vec, } -pub fn build(config: &SlidesConfig, statics: &Path, dist: &Path) -> Result<()> { +pub fn build( + rng: &mut rand::rngs::StdRng, + config: &SlidesConfig, + statics: &Path, + dist: &Path, +) -> Result<()> { + let back_alley_name = b"abcdefghijklmnopqrstuvwxyz" + .choose_multiple(rng, 6) + .map(|&c| char::from_u32(c.into()).unwrap()) + .collect::(); + + let back_alley_name = format!("back-alley-{back_alley_name}.html"); + utils::cp_content(&statics.join("root"), dist).wrap_err("copying root files")?; + let back_alley = dist.join("back-alley.html"); + std::fs::copy(&back_alley, dist.join(&back_alley_name)).wrap_err("copying back-alley.html")?; + fs::remove_file(back_alley).wrap_err("deleting normal back-alley.html")?; + + let index_html = dist.join("index.html"); + let index = fs::read_to_string(&index_html).wrap_err("reading index.html")?; + fs::write( + index_html, + index.replace("back-alley.html", &back_alley_name), + ) + .wrap_err("writing back index.html")?; + let slide_html = Slides { talks: config.talks.clone(), } diff --git a/src/main.rs b/src/main.rs index d8c1999..109fb1e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ use color_eyre::{ Result, }; use notify::{RecursiveMode, Watcher}; +use rand::SeedableRng; use serde::Deserialize; use tracing::level_filters::LevelFilter; use tracing_subscriber::EnvFilter; @@ -74,14 +75,18 @@ fn main() -> Result<()> { Ok(()) } Some("watch") => watch(root), - Some("build") => build(root), + Some("build") => build(&mut rand::rngs::StdRng::from_entropy(), root), Some(cmd) => bail!("invalid subcommand {cmd}"), None => bail!("no subcommand provided"), } } fn watch(root: &'static Path) -> Result<()> { - build(root).wrap_err("initial build")?; + let seed: u64 = rand::random(); + + let rng = move || rand::rngs::StdRng::seed_from_u64(seed); + + build(&mut rng(), root).wrap_err("initial build")?; let (send, recv) = std::sync::mpsc::sync_channel(1); let mut watcher = notify::recommended_watcher(move |res| match res { Ok(_) => { @@ -130,7 +135,7 @@ fn watch(root: &'static Path) -> Result<()> { last = now; info!("Received update, rebuilding"); - if let Err(e) = build(root) { + if let Err(e) = build(&mut rng(), root) { error!(?e); } } @@ -139,7 +144,7 @@ fn watch(root: &'static Path) -> Result<()> { .map_err(|_| eyre!("build thread panicked")) } -fn build(root: &Path) -> Result<()> { +fn build(rng: &mut rand::rngs::StdRng, root: &Path) -> Result<()> { 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")?; @@ -152,7 +157,13 @@ fn build(root: &Path) -> Result<()> { submodule::sync(&submodules_path, &sub_config).wrap_err("syncing subtrees")?; let dist_path = root.join("dist"); - build::assemble_website(&config, &root.join("static"), &submodules_path, &dist_path)?; + build::assemble_website( + rng, + &config, + &root.join("static"), + &submodules_path, + &dist_path, + )?; Ok(()) } diff --git a/static/root/index.html b/static/root/index.html index 4a1c832..27e6d98 100644 --- a/static/root/index.html +++ b/static/root/index.html @@ -97,8 +97,8 @@

in addition to all the other stuff mentioned above, i also have some random projects hosted on my server. they are pretty bad and i won't promote them this openly, but you - will be able to find them if you really want to. some people have been saying - that there might be a secret back alley somewhere... + will be able to find them if you really want to. some people have been saying that there + might be a secret back alley somewhere...