From 659bb5da636c0c0d4e386e9df5de449380d6cc5d Mon Sep 17 00:00:00 2001 From: quirinecker Date: Mon, 10 Nov 2025 16:46:43 +0100 Subject: [PATCH] wip docs dir --- src/app/commands/build.rs | 8 ++++--- .../commands/executions/build_execution.rs | 24 +++++++++---------- src/app/commands/serve.rs | 12 +++++----- src/app/mod.rs | 4 ++-- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/app/commands/build.rs b/src/app/commands/build.rs index ce31e40..83e8fcd 100644 --- a/src/app/commands/build.rs +++ b/src/app/commands/build.rs @@ -1,6 +1,8 @@ +use crate::app::config::config::Config; + use super::executions::build_execution::BuildExecution; -pub async fn build(offline_reveal: bool) -> () { - let mut build_execution = BuildExecution::new(); - build_execution.execute(offline_reveal).await.expect("build failed") +pub async fn build(config: &Config) -> () { + let mut build_execution = BuildExecution::new(&config.docs_dir); + build_execution.execute(&config).await.expect("build failed") } diff --git a/src/app/commands/executions/build_execution.rs b/src/app/commands/executions/build_execution.rs index ed6475e..98b4847 100644 --- a/src/app/commands/executions/build_execution.rs +++ b/src/app/commands/executions/build_execution.rs @@ -1,28 +1,28 @@ use std::{ - io::Cursor, - path::PathBuf + fmt::format, io::Cursor, path::PathBuf }; use crate::app::{ - build::{docki_build, DockiBuildResult}, - fs_util::{self, create_dir_recursive}, log::display_status, + build::{DockiBuildResult, docki_build}, config::config::Config, fs_util::{self, create_dir_recursive}, log::display_status }; pub struct BuildExecution { progress: usize, goal: usize, + docs_dir: String } impl BuildExecution { - pub fn new() -> Self { + pub fn new(docs_dir: &str) -> Self { return BuildExecution { progress: 0, goal: 0, + docs_dir: docs_dir.to_string() }; } - pub async fn execute(&mut self, offline_reveal: bool) -> Result<(), String> { - let path = "./docs/".to_string(); + pub async fn execute(&mut self, config: &Config) -> Result<(), String> { + let path = self.docs_dir.to_string(); if !fs_util::directory_exists(&path) { 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 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 { return Ok(()) } @@ -46,7 +46,7 @@ impl BuildExecution { let reveal_version = "5.2.1"; 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(); let Ok(response) = reqwest::get(target).await else { @@ -57,7 +57,7 @@ impl BuildExecution { 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() { return Err("could not write extracted archive to disk".to_string()); diff --git a/src/app/commands/serve.rs b/src/app/commands/serve.rs index 641b9d9..9ecbfea 100644 --- a/src/app/commands/serve.rs +++ b/src/app/commands/serve.rs @@ -7,16 +7,16 @@ use notify::{ }; 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) { - build(false).await; - tokio::join!(watch_and_build(), start_server(port)); +pub async fn serve(config: &Config) { + build(config).await; + tokio::join!(watch_and_build(&config.docs_dir), start_server(config.port)); } -async fn watch_and_build() { - watch(Path::new("./docs")) +async fn watch_and_build(docs_dir: &str) { + watch(Path::new(docs_dir)) .await .expect("something went wrong") } diff --git a/src/app/mod.rs b/src/app/mod.rs index 698f216..ee0ae45 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -26,10 +26,10 @@ impl App { Self::setup_environment_variables(); match args.command { - CommandArg::Build { .. } => build(config.offline_reveal).await, + CommandArg::Build { .. } => build(&config).await, CommandArg::Health => health(), CommandArg::InstallReveal => install_reveal().await, - CommandArg::Serve { .. } => serve(config.port).await, + CommandArg::Serve { .. } => serve(&config).await, CommandArg::Completions { shell } => completions(shell) }; }