wip docs dir

This commit is contained in:
2025-11-10 16:46:43 +01:00
parent 24e1ade129
commit 659bb5da63
4 changed files with 25 additions and 23 deletions

View File

@@ -1,6 +1,8 @@
use crate::app::config::config::Config;
use super::executions::build_execution::BuildExecution; use super::executions::build_execution::BuildExecution;
pub async fn build(offline_reveal: bool) -> () { pub async fn build(config: &Config) -> () {
let mut build_execution = BuildExecution::new(); let mut build_execution = BuildExecution::new(&config.docs_dir);
build_execution.execute(offline_reveal).await.expect("build failed") build_execution.execute(&config).await.expect("build failed")
} }

View File

@@ -1,28 +1,28 @@
use std::{ use std::{
io::Cursor, fmt::format, io::Cursor, path::PathBuf
path::PathBuf
}; };
use crate::app::{ use crate::app::{
build::{docki_build, DockiBuildResult}, build::{DockiBuildResult, docki_build}, config::config::Config, fs_util::{self, create_dir_recursive}, log::display_status
fs_util::{self, create_dir_recursive}, log::display_status,
}; };
pub struct BuildExecution { pub struct BuildExecution {
progress: usize, progress: usize,
goal: usize, goal: usize,
docs_dir: String
} }
impl BuildExecution { impl BuildExecution {
pub fn new() -> Self { pub fn new(docs_dir: &str) -> Self {
return BuildExecution { return BuildExecution {
progress: 0, progress: 0,
goal: 0, goal: 0,
docs_dir: docs_dir.to_string()
}; };
} }
pub async fn execute(&mut self, offline_reveal: bool) -> Result<(), String> { pub async fn execute(&mut self, config: &Config) -> Result<(), String> {
let path = "./docs/".to_string(); let path = self.docs_dir.to_string();
if !fs_util::directory_exists(&path) { if !fs_util::directory_exists(&path) {
return Err( return Err(
@@ -30,15 +30,15 @@ impl BuildExecution {
); );
} }
if let Err(error) = Self::prepare(offline_reveal).await { if let Err(error) = self.prepare(config.offline_reveal).await {
return Err(error); return Err(error);
} }
return self.build_dir(&path, offline_reveal); return self.build_dir(&path, config.offline_reveal);
} }
async fn prepare(offline_reveal: bool) -> Result<(), String> { async fn prepare(&self, offline_reveal: bool) -> Result<(), String> {
if !offline_reveal { if !offline_reveal {
return Ok(()) return Ok(())
} }
@@ -46,7 +46,7 @@ impl BuildExecution {
let reveal_version = "5.2.1"; let reveal_version = "5.2.1";
let target = format!("https://github.com/hakimel/reveal.js/archive/{reveal_version}.zip"); let target = format!("https://github.com/hakimel/reveal.js/archive/{reveal_version}.zip");
create_dir_recursive("./docs/slides"); create_dir_recursive(format!("{}/slides", self.docs_dir).as_str());
reqwest::get(target.clone()).await.unwrap(); reqwest::get(target.clone()).await.unwrap();
let Ok(response) = reqwest::get(target).await else { let Ok(response) = reqwest::get(target).await else {
@@ -57,7 +57,7 @@ impl BuildExecution {
return Err("could not extract bytes".to_string()) return Err("could not extract bytes".to_string())
}; };
let out = PathBuf::from("./docs/slides/revealjs"); let out = PathBuf::from(format!("{}/slides/revealjs", self.docs_dir));
if zip_extract::extract(Cursor::new(bytes), &out, true).is_err() { if zip_extract::extract(Cursor::new(bytes), &out, true).is_err() {
return Err("could not write extracted archive to disk".to_string()); return Err("could not write extracted archive to disk".to_string());

View File

@@ -7,16 +7,16 @@ use notify::{
}; };
use std::{env, path::Path}; use std::{env, path::Path};
use crate::app::{ watcher::watcher, build::{docki_build, DockiBuildResult}, commands::build::build, log::display_status}; use crate::app::{ build::{DockiBuildResult, docki_build}, commands::build::build, config::config::Config, log::display_status, watcher::watcher};
pub async fn serve(port: u16) { pub async fn serve(config: &Config) {
build(false).await; build(config).await;
tokio::join!(watch_and_build(), start_server(port)); tokio::join!(watch_and_build(&config.docs_dir), start_server(config.port));
} }
async fn watch_and_build() { async fn watch_and_build(docs_dir: &str) {
watch(Path::new("./docs")) watch(Path::new(docs_dir))
.await .await
.expect("something went wrong") .expect("something went wrong")
} }

View File

@@ -26,10 +26,10 @@ impl App {
Self::setup_environment_variables(); Self::setup_environment_variables();
match args.command { match args.command {
CommandArg::Build { .. } => build(config.offline_reveal).await, CommandArg::Build { .. } => build(&config).await,
CommandArg::Health => health(), CommandArg::Health => health(),
CommandArg::InstallReveal => install_reveal().await, CommandArg::InstallReveal => install_reveal().await,
CommandArg::Serve { .. } => serve(config.port).await, CommandArg::Serve { .. } => serve(&config).await,
CommandArg::Completions { shell } => completions(shell) CommandArg::Completions { shell } => completions(shell)
}; };
} }