random name for back alley

This commit is contained in:
nora 2024-01-21 21:16:24 +01:00
parent 9f9120dc27
commit 2d2c820510
6 changed files with 95 additions and 9 deletions

View file

@ -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)?;

View file

@ -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<Talk>,
}
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::<String>();
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(),
}