From 78e2acb32537b00c8807528eea0b847953570d90 Mon Sep 17 00:00:00 2001 From: quirinecker Date: Sun, 9 Nov 2025 14:37:31 +0100 Subject: [PATCH 1/4] using relative path for reveal again because of issues with github page s --- src/app/build/asciidoctor.rs | 58 +++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/app/build/asciidoctor.rs b/src/app/build/asciidoctor.rs index 0f15ef6..9b90f1a 100644 --- a/src/app/build/asciidoctor.rs +++ b/src/app/build/asciidoctor.rs @@ -1,3 +1,4 @@ +use regex::Regex; use std::process; fn exec_command(command: &mut process::Command) -> Result<(), String> { @@ -29,7 +30,8 @@ fn asciidoctor_docs(in_path: &str, out_path: &str) -> process::Command { fn asciidoctor_slides(in_path: &str, out_path: &str) -> process::Command { let mut command = process::Command::new(format!("asciidoctor-revealjs")); - let revealjs_path = "/slides/revealjs"; + let out_dir = parent_path(out_path); + let revealjs_path = path_between(out_dir.to_string(), "./dist/slides/revealjs".to_string()); command .arg(format!("{in_path}")) @@ -40,6 +42,60 @@ fn asciidoctor_slides(in_path: &str, out_path: &str) -> process::Command { return command; } +fn parent_path(child_path: &str) -> String { + let split: Vec<&str> = child_path.split("/").collect(); + let slice = &split[..split.len() - 1]; + return slice.join("/"); +} + +pub fn path_between(from: String, to: String) -> String { + let from_segments = transform_input_to_clone_split(&from); + let to_segments = transform_input_to_clone_split(&to); + let last_matching_index = matching_from_start(&from_segments, &to_segments); + let number_of_backs = from_segments.len() - last_matching_index; + let mut path_between = path_back(number_of_backs); + let path_to_to_path = &to_segments[last_matching_index..]; + path_between.push_str(&path_to_to_path.join("/")); + return path_between; +} + +fn transform_input_to_clone_split(input: &String) -> Vec { + let regex = Regex::new(r"/$").unwrap(); + let first_transformation = input.clone().replace("./", ""); + return regex + .replace_all(&first_transformation, "") + .to_string() + .split("/") + .collect::>() + .iter() + .map(|s| s.to_string()) + .collect(); +} + +fn path_back(count: usize) -> String { + let mut path = "".to_string(); + + for _ in 0..count { + path.push_str("../"); + } + + return path; +} + +pub fn matching_from_start(from_segments: &Vec, to_segments: &Vec) -> usize { + for (index, from_segment) in from_segments.iter().enumerate() { + if let Some(to_segment) = to_segments.get(index) { + if from_segment != to_segment { + return index; + } + } else { + return index; + } + } + + return from_segments.len(); +} + pub fn build_doc(in_path: &str, out_path: &str) -> Result<(), String> { let mut command = asciidoctor_docs(in_path, out_path); return exec_command(&mut command); From 926944e8dd35ccc0fb6d8d1471d5abb0741a095d Mon Sep 17 00:00:00 2001 From: quirinecker Date: Sun, 9 Nov 2025 19:20:58 +0100 Subject: [PATCH 2/4] revealjs default now cdn. added flag for downloading for offline use --- src/app/args/structure.rs | 5 ++++- src/app/build/asciidoctor.rs | 12 +++++++---- src/app/build/mod.rs | 9 ++++++-- src/app/commands/build.rs | 4 ++-- .../commands/executions/build_execution.rs | 21 ++++++++++++------- src/app/commands/serve.rs | 5 +++-- src/app/mod.rs | 2 +- 7 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/app/args/structure.rs b/src/app/args/structure.rs index f01201a..df619c4 100644 --- a/src/app/args/structure.rs +++ b/src/app/args/structure.rs @@ -16,7 +16,10 @@ pub enum ShellArg { #[derive(Subcommand)] pub enum CommandArg { /// Builds the documentation into a dist folder - Build, + Build { + #[arg(short, long)] + offline_reveal: bool, + }, /// Checks if everything required for docki is installed Health, /// Helper command for installing asciidoctor-reveal-js diff --git a/src/app/build/asciidoctor.rs b/src/app/build/asciidoctor.rs index 9b90f1a..1b44433 100644 --- a/src/app/build/asciidoctor.rs +++ b/src/app/build/asciidoctor.rs @@ -28,10 +28,14 @@ fn asciidoctor_docs(in_path: &str, out_path: &str) -> process::Command { return command; } -fn asciidoctor_slides(in_path: &str, out_path: &str) -> process::Command { +fn asciidoctor_slides(in_path: &str, out_path: &str, offline_reveal: bool) -> process::Command { let mut command = process::Command::new(format!("asciidoctor-revealjs")); let out_dir = parent_path(out_path); - let revealjs_path = path_between(out_dir.to_string(), "./dist/slides/revealjs".to_string()); + let revealjs_path = if offline_reveal { + path_between(out_dir.to_string(), "./dist/slides/revealjs".to_string()) + } else { + "https://cdn.jsdelivr.net/npm/reveal.js@5.2.1".to_string() + }; command .arg(format!("{in_path}")) @@ -101,8 +105,8 @@ pub fn build_doc(in_path: &str, out_path: &str) -> Result<(), String> { return exec_command(&mut command); } -pub fn build_slide(in_path: &str, out_path: &str) -> Result<(), String> { - let mut command = asciidoctor_slides(in_path, out_path); +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); return exec_command(&mut command); } diff --git a/src/app/build/mod.rs b/src/app/build/mod.rs index 7071c99..f3d72f9 100644 --- a/src/app/build/mod.rs +++ b/src/app/build/mod.rs @@ -6,12 +6,12 @@ use super::fs_util; pub mod asciidoctor; -pub fn docki_build(in_path: &str) -> DockiBuildResult { +pub fn docki_build(in_path: &str, offline_reveal: bool) -> DockiBuildResult { let out_path = in_path.replace("/docs/", "/dist/"); let convert_out_path = out_path.replace(".adoc", ".html"); if in_path.starts_with("./docs/slides/") && in_path.ends_with(".adoc") { - if let Err(err) = build_slide(&in_path, &convert_out_path) { + if let Err(err) = build_slide(&in_path, &convert_out_path, offline_reveal) { return DockiBuildResult::Err(err); } @@ -23,6 +23,10 @@ pub fn docki_build(in_path: &str) -> DockiBuildResult { DockiBuildResult::Doc(convert_out_path) } else { + if in_path.starts_with("./docs/slides/revealjs") && !offline_reveal { + return DockiBuildResult::Silent; + } + if let Err(err) = copy(&in_path, &out_path) { return DockiBuildResult::Err(err); } @@ -46,4 +50,5 @@ pub enum DockiBuildResult { Doc(String), Copy(String), Err(String), + Silent, } diff --git a/src/app/commands/build.rs b/src/app/commands/build.rs index c3fe698..ce31e40 100644 --- a/src/app/commands/build.rs +++ b/src/app/commands/build.rs @@ -1,6 +1,6 @@ use super::executions::build_execution::BuildExecution; -pub async fn build() -> () { +pub async fn build(offline_reveal: bool) -> () { let mut build_execution = BuildExecution::new(); - build_execution.execute().await.expect("build failed") + build_execution.execute(offline_reveal).await.expect("build failed") } diff --git a/src/app/commands/executions/build_execution.rs b/src/app/commands/executions/build_execution.rs index 37f3041..8107ea8 100644 --- a/src/app/commands/executions/build_execution.rs +++ b/src/app/commands/executions/build_execution.rs @@ -21,7 +21,7 @@ impl BuildExecution { }; } - pub async fn execute(&mut self) -> Result<(), String> { + pub async fn execute(&mut self, offline_reveal: bool) -> Result<(), String> { let path = "./docs/".to_string(); if !fs_util::directory_exists(&path) { @@ -30,21 +30,25 @@ impl BuildExecution { ); } - if let Err(error) = Self::prepare().await { + if let Err(error) = Self::prepare(offline_reveal).await { return Err(error); } - return self.build_dir(&path); + return self.build_dir(&path, offline_reveal); } - async fn prepare() -> Result<(), String> { + async fn prepare(offline_reveal: bool) -> Result<(), String> { + if !offline_reveal { + return Ok(()) + } + let reveal_version = "5.2.1"; let target = format!("https://github.com/hakimel/reveal.js/archive/{reveal_version}.zip"); create_dir_recursive("./docs/slides"); - let response = reqwest::get(target.clone()).await.unwrap(); + reqwest::get(target.clone()).await.unwrap(); let Ok(response) = reqwest::get(target).await else { return Err("could not downlaod revealjs".to_string()) }; @@ -62,7 +66,7 @@ impl BuildExecution { return Ok(()); } - fn build_dir(&mut self, path: &str) -> Result<(), String> { + fn build_dir(&mut self, path: &str, offline_reveal: bool) -> Result<(), String> { let result = fs_util::fetch_paths_recursive(&path); let Ok(paths) = result else { @@ -72,7 +76,7 @@ impl BuildExecution { for (index, in_path) in paths.iter().enumerate() { self.progress = index + 1; self.goal = paths.len(); - let result = docki_build(&in_path); + let result = docki_build(&in_path, offline_reveal); match result { DockiBuildResult::Err(err) => { @@ -81,7 +85,8 @@ impl BuildExecution { }, DockiBuildResult::Copy(out_path) => self.display_building_status("Copy", &in_path, &out_path), DockiBuildResult::Slide(out_path) => self.display_building_status("Slide", &in_path, &out_path), - DockiBuildResult::Doc(out_path) => self.display_building_status("Doc", &in_path, &out_path) + DockiBuildResult::Doc(out_path) => self.display_building_status("Doc", &in_path, &out_path), + DockiBuildResult::Silent => () } } diff --git a/src/app/commands/serve.rs b/src/app/commands/serve.rs index 4a7e74e..a15f2be 100644 --- a/src/app/commands/serve.rs +++ b/src/app/commands/serve.rs @@ -11,7 +11,7 @@ use crate::app::{ watcher::watcher, build::{docki_build, DockiBuildResult}, comm pub async fn serve(port: Option) { - build().await; + build(false).await; tokio::join!(watch_and_build(), start_server(port)); } @@ -65,7 +65,7 @@ fn build_file(paths: Vec) { .expect(invalid_path_message); let in_path = format!("./{}", in_path); - let result = docki_build(&in_path); + let result = docki_build(&in_path, false); match result { DockiBuildResult::Slide(out_path) => display_rebuilding_status("Slide", &in_path, &out_path), @@ -75,6 +75,7 @@ fn build_file(paths: Vec) { display_rebuilding_status("Error", &in_path, ""); println!("{}", err); }, + DockiBuildResult::Silent => () } } diff --git a/src/app/mod.rs b/src/app/mod.rs index 0ba9bfb..1b33424 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -23,7 +23,7 @@ impl App { Self::setup_environment_variables(); match args.command { - CommandArg::Build => build().await, + CommandArg::Build { offline_reveal } => build(offline_reveal).await, CommandArg::Health => health(), CommandArg::InstallReveal => install_reveal().await, CommandArg::Serve { port } => serve(port).await, From cc65ce3e7c19dd9adbaaad1fb4b2f679b5f92dec Mon Sep 17 00:00:00 2001 From: quirinecker Date: Sun, 9 Nov 2025 19:26:05 +0100 Subject: [PATCH 3/4] updated help texts --- src/app/args/structure.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/args/structure.rs b/src/app/args/structure.rs index df619c4..41a915a 100644 --- a/src/app/args/structure.rs +++ b/src/app/args/structure.rs @@ -17,12 +17,14 @@ pub enum ShellArg { pub enum CommandArg { /// Builds the documentation into a dist folder Build { + /// When set to true, docki will download revealjs before building the documentation. + /// Otherwise it will use the cdn for revealjs #[arg(short, long)] offline_reveal: bool, }, /// Checks if everything required for docki is installed Health, - /// Helper command for installing asciidoctor-reveal-js + /// Deprecated: Helper command for installing asciidoctor-reveal-js InstallReveal, /// Starts a Webserver with the live preview of the Documentation Serve { From 1a009bac611049cfc20695958ddcdffa3c5fae62 Mon Sep 17 00:00:00 2001 From: quirinecker Date: Sun, 9 Nov 2025 19:27:02 +0100 Subject: [PATCH 4/4] incremented version to 1.2.3 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2431bc2..0ee4815 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -859,7 +859,7 @@ checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" [[package]] name = "docki" -version = "1.2.2" +version = "1.2.3" dependencies = [ "bytes", "clap 4.1.8", diff --git a/Cargo.toml b/Cargo.toml index 1090909..ee79201 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "docki" -version = "1.2.2" +version = "1.2.3" edition = "2021" description = "cli for building and publishing documentation using asciidoctor" license-file = "LICENSE.txt"