mirror of
https://github.com/Noratrieb/website.git
synced 2026-01-14 17:05:02 +01:00
static stuff
This commit is contained in:
parent
56da12a5bc
commit
148a5352a3
8 changed files with 237 additions and 2 deletions
|
|
@ -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(())
|
||||
|
|
|
|||
29
src/build/statics.rs
Normal file
29
src/build/statics.rs
Normal file
|
|
@ -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<String>,
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
12
src/main.rs
12
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>(&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(())
|
||||
}
|
||||
|
|
|
|||
15
src/utils.rs
15
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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue