From 3ae1b2cc6e0ae3b89f81adf5da4075ea3242b0fb Mon Sep 17 00:00:00 2001 From: quirinecker Date: Thu, 13 Nov 2025 09:24:46 +0100 Subject: [PATCH] finished rewrite. custon folders work now --- res/test/docki.config.toml | 2 +- src/app/build/asciidoctor.rs | 17 +++++++++++------ src/app/build/mod.rs | 6 +++--- src/app/commands/serve.rs | 2 +- src/app/config/arguments.rs | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/res/test/docki.config.toml b/res/test/docki.config.toml index 88b2a2a..ea98a64 100644 --- a/res/test/docki.config.toml +++ b/res/test/docki.config.toml @@ -1,3 +1,3 @@ -docs_dir = "./docs" +docs_dir = "./asciidocs" port = 6969 offline_reveal = false diff --git a/src/app/build/asciidoctor.rs b/src/app/build/asciidoctor.rs index aeb0d94..bcf2f29 100644 --- a/src/app/build/asciidoctor.rs +++ b/src/app/build/asciidoctor.rs @@ -1,6 +1,8 @@ use regex::Regex; use std::process; +use crate::app::config::config::Config; + fn exec_command(command: &mut process::Command) -> Result<(), String> { let result = command.output(); @@ -32,11 +34,14 @@ fn asciidoctor_docs(in_path: &str, out_path: &str) -> process::Command { return command; } -fn asciidoctor_slides(in_path: &str, out_path: &str, offline_reveal: bool) -> process::Command { +fn asciidoctor_slides(in_path: &str, out_path: &str, config: &Config) -> process::Command { let mut command = process::Command::new(format!("asciidoctor-revealjs")); let out_dir = parent_path(out_path); - let revealjs_path = if offline_reveal { - path_between(out_dir.to_string(), "./dist/slides/revealjs".to_string()) + let revealjs_path = if config.offline_reveal { + path_between( + out_dir.to_string(), + format!("{}/slides/revealjs", config.output_dir), + ) } else { "https://cdn.jsdelivr.net/npm/reveal.js@5.2.1".to_string() }; @@ -104,13 +109,13 @@ pub fn matching_from_start(from_segments: &Vec, to_segments: &Vec Result<(), String> { +pub fn build_doc(in_path: &str, out_path: &str, _: &Config) -> Result<(), String> { let mut command = asciidoctor_docs(in_path, out_path); return exec_command(&mut command); } -pub fn build_slide(in_path: &str, out_path: &str, offline_reveal: bool) -> Result<(), String> { - let mut command = asciidoctor_slides(in_path, out_path, offline_reveal); +pub fn build_slide(in_path: &str, out_path: &str, config: &Config) -> Result<(), String> { + let mut command = asciidoctor_slides(in_path, out_path, config); return exec_command(&mut command); } diff --git a/src/app/build/mod.rs b/src/app/build/mod.rs index 9e6a7a7..c9dd38b 100644 --- a/src/app/build/mod.rs +++ b/src/app/build/mod.rs @@ -99,17 +99,17 @@ impl <'a> DockiBuilder <'a> { /// Builds a single file without a pretty output pub fn build_file(&self, path: &str) -> DockiBuildResult { - let out_path = path.replace(&self.config.input_dir, "./dist"); + let out_path = path.replace(&self.config.input_dir, &self.config.output_dir); let convert_out_path = out_path.replace(".adoc", ".html"); if path.starts_with(format!("{}/slides/", &self.config.input_dir).as_str()) && path.ends_with(".adoc") { - if let Err(err) = build_slide(&path, &convert_out_path, self.config.offline_reveal) { + if let Err(err) = build_slide(&path, &convert_out_path, self.config) { return DockiBuildResult::Err(err); } DockiBuildResult::Slide(convert_out_path) } else if path.ends_with(".adoc") { - if let Err(err) = build_doc(&path, &convert_out_path) { + if let Err(err) = build_doc(&path, &convert_out_path, self.config) { return DockiBuildResult::Err(err); } diff --git a/src/app/commands/serve.rs b/src/app/commands/serve.rs index 541a187..c46babb 100644 --- a/src/app/commands/serve.rs +++ b/src/app/commands/serve.rs @@ -46,7 +46,7 @@ impl <'a> Server <'a> { hyperlink ); - let Ok(()) = listen("localhost", self.config.port, "./dist").await else { + let Ok(()) = listen("localhost", self.config.port, self.config.output_dir.clone()).await else { panic!("could not start server") }; } diff --git a/src/app/config/arguments.rs b/src/app/config/arguments.rs index 8d50510..617a218 100644 --- a/src/app/config/arguments.rs +++ b/src/app/config/arguments.rs @@ -33,7 +33,7 @@ pub enum ShellArg { #[derive(Subcommand)] pub enum CommandArg { - /// Builds the documentation into a dist folder + /// Builds the documentation into the specified output_dir Build { /// When set to true, docki will download revealjs before building the documentation. /// Otherwise it will use the cdn for revealjs