This commit is contained in:
nora 2024-01-18 20:47:46 +01:00
parent 43d792e148
commit 89b3e2df37
13 changed files with 211 additions and 40 deletions

37
src/build/blog.rs Normal file
View file

@ -0,0 +1,37 @@
//! Builds my blog, built with hugo.
use std::{path::Path, process::Command};
use color_eyre::{eyre::Context, Result};
use crate::utils;
pub fn build(blog: &Path, dist: &Path) -> Result<()> {
info!("Building blog with hugo");
utils::run_process(
Command::new("git")
.args(&["submodule", "init"])
.current_dir(&blog),
)?;
utils::run_process(
Command::new("git")
.args(&["submodule", "update"])
.current_dir(&blog),
)?;
// Patch config
let config =
std::fs::read_to_string(blog.join("config.toml")).wrap_err("reading blog config")?;
let config = config.replace("baseURL = \"/\"", "baseURL = \"/blog/\"");
std::fs::write(blog.join("config.toml"), config).wrap_err("writing patched config.toml")?;
utils::run_process(
Command::new("hugo")
.args(&["--minify", "--destination", dist.to_str().unwrap()])
.current_dir(&blog),
)?;
Ok(())
}

22
src/build/mod.rs Normal file
View file

@ -0,0 +1,22 @@
//! This module assembles and builds the website.
mod blog;
mod slides;
use std::path::Path;
use color_eyre::{eyre::Context, Result};
use crate::Config;
pub fn assemble_website(config: &Config, submodules: &Path, dist: &Path) -> Result<()> {
blog::build(&submodules.join("blog"), &dist.join("blog")).wrap_err("building blog")?;
slides::build(
&config.slides,
&submodules.join("slides"),
&dist.join("slides"),
)
.wrap_err("building slides")?;
Ok(())
}

26
src/build/slides.rs Normal file
View file

@ -0,0 +1,26 @@
//! Moving the slides from the reveal.js repo
//! The setup is currently a bit bad but I'm not sure what the best solution would look like.
use std::path::Path;
use color_eyre::{eyre::WrapErr, Result};
use crate::{utils, SlidesConfig};
pub fn build(config: &SlidesConfig, slides: &Path, dist: &Path) -> Result<()> {
info!("Building slides");
debug!("Copying reveal.js dist");
utils::cp_r(&slides.join("dist"), &dist.join("dist")).wrap_err("copying reveal.js dist")?;
utils::cp_r(&slides.join("plugin"), &dist.join("plugin")).wrap_err("copying reveal.js dist")?;
for talk in &config.talks {
let path = slides.join(talk);
let dist = dist.join(talk);
utils::cp_r(&path, &dist).wrap_err("copying slide data")?;
}
Ok(())
}