diff --git a/src/compiler.rs b/src/compiler.rs index aceebbb6..1f1b1bd4 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -199,10 +199,30 @@ impl AmberCompiler { } let now = Local::now().format("%Y-%m-%d %H:%M:%S").to_string(); - let header = include_str!("header.sh") + + let header_template = + if let Ok(dynamic) = env::var("AMBER_HEADER") { + fs::read_to_string(dynamic.to_string()).expect(format!("Couldn't read the dynamic header file from {dynamic}").as_str()) + } else { + include_str!("header.sh").to_string() + }; + + let footer_template = + if let Ok(dynamic) = env::var("AMBER_FOOTER") { + fs::read_to_string(dynamic.to_string()).expect(format!("Couldn't read the dynamic footer file from {dynamic}").as_str()) + } else { + String::new() + }; + + let header = header_template + .replace("{{ version }}", env!("CARGO_PKG_VERSION")) + .replace("{{ date }}", now.as_str()); + + let footer = footer_template .replace("{{ version }}", env!("CARGO_PKG_VERSION")) .replace("{{ date }}", now.as_str()); - Ok(format!("{}{}", header, result)) + + Ok(format!("{}\n{}\n{}", header, result, footer)) } pub fn document(&self, block: Block, meta: ParserMetadata, output: Option) { diff --git a/src/header.sh b/src/header.sh index af53f2f7..9d1af4bf 100644 --- a/src/header.sh +++ b/src/header.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash # Written in [Amber](https://amber-lang.com/) # version: {{ version }} -# date: {{ date }} +# date: {{ date }} \ No newline at end of file