mirror of
https://github.com/Noratrieb/website.git
synced 2026-01-14 17:05:02 +01:00
random name for back alley
This commit is contained in:
parent
9f9120dc27
commit
2d2c820510
6 changed files with 95 additions and 9 deletions
48
Cargo.lock
generated
48
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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)?;
|
||||
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
}
|
||||
|
|
|
|||
21
src/main.rs
21
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>(&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(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,8 +97,8 @@
|
|||
<p>
|
||||
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 <span role="button" class="hint">b</span>ack alley somewhere...
|
||||
will be able to find them if you really want to. some people have been saying that there
|
||||
might be a secret <span role="button" class="hint">b</span>ack alley somewhere...
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue