finished rewrite. custon folders work now
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
docs_dir = "./docs"
|
docs_dir = "./asciidocs"
|
||||||
port = 6969
|
port = 6969
|
||||||
offline_reveal = false
|
offline_reveal = false
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
|
use crate::app::config::config::Config;
|
||||||
|
|
||||||
fn exec_command(command: &mut process::Command) -> Result<(), String> {
|
fn exec_command(command: &mut process::Command) -> Result<(), String> {
|
||||||
let result = command.output();
|
let result = command.output();
|
||||||
|
|
||||||
@@ -32,11 +34,14 @@ fn asciidoctor_docs(in_path: &str, out_path: &str) -> process::Command {
|
|||||||
return 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 mut command = process::Command::new(format!("asciidoctor-revealjs"));
|
||||||
let out_dir = parent_path(out_path);
|
let out_dir = parent_path(out_path);
|
||||||
let revealjs_path = if offline_reveal {
|
let revealjs_path = if config.offline_reveal {
|
||||||
path_between(out_dir.to_string(), "./dist/slides/revealjs".to_string())
|
path_between(
|
||||||
|
out_dir.to_string(),
|
||||||
|
format!("{}/slides/revealjs", config.output_dir),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
"https://cdn.jsdelivr.net/npm/reveal.js@5.2.1".to_string()
|
"https://cdn.jsdelivr.net/npm/reveal.js@5.2.1".to_string()
|
||||||
};
|
};
|
||||||
@@ -104,13 +109,13 @@ pub fn matching_from_start(from_segments: &Vec<String>, to_segments: &Vec<String
|
|||||||
return from_segments.len();
|
return from_segments.len();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_doc(in_path: &str, out_path: &str) -> Result<(), String> {
|
pub fn build_doc(in_path: &str, out_path: &str, _: &Config) -> Result<(), String> {
|
||||||
let mut command = asciidoctor_docs(in_path, out_path);
|
let mut command = asciidoctor_docs(in_path, out_path);
|
||||||
return exec_command(&mut command);
|
return exec_command(&mut command);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_slide(in_path: &str, out_path: &str, offline_reveal: bool) -> Result<(), String> {
|
pub fn build_slide(in_path: &str, out_path: &str, config: &Config) -> Result<(), String> {
|
||||||
let mut command = asciidoctor_slides(in_path, out_path, offline_reveal);
|
let mut command = asciidoctor_slides(in_path, out_path, config);
|
||||||
return exec_command(&mut command);
|
return exec_command(&mut command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,17 +99,17 @@ impl <'a> DockiBuilder <'a> {
|
|||||||
|
|
||||||
/// Builds a single file without a pretty output
|
/// Builds a single file without a pretty output
|
||||||
pub fn build_file(&self, path: &str) -> DockiBuildResult {
|
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");
|
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 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);
|
return DockiBuildResult::Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
DockiBuildResult::Slide(convert_out_path)
|
DockiBuildResult::Slide(convert_out_path)
|
||||||
} else if path.ends_with(".adoc") {
|
} 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);
|
return DockiBuildResult::Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ impl <'a> Server <'a> {
|
|||||||
hyperlink
|
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")
|
panic!("could not start server")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ pub enum ShellArg {
|
|||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum CommandArg {
|
pub enum CommandArg {
|
||||||
/// Builds the documentation into a dist folder
|
/// Builds the documentation into the specified output_dir
|
||||||
Build {
|
Build {
|
||||||
/// When set to true, docki will download revealjs before building the documentation.
|
/// When set to true, docki will download revealjs before building the documentation.
|
||||||
/// Otherwise it will use the cdn for revealjs
|
/// Otherwise it will use the cdn for revealjs
|
||||||
|
|||||||
Reference in New Issue
Block a user