Skip to content

Commit 4ea726b

Browse files
authored
Avoid copying input file (#31)
Fixes #26 and while also fixing #14 in a simpler way.
1 parent 8e17fef commit 4ea726b

File tree

2 files changed

+3
-39
lines changed

2 files changed

+3
-39
lines changed

src/image.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub fn generate_images(input: &PathBuf, dir: &str) {
1212
.arg("compile")
1313
.arg("--format=png")
1414
.arg("--ppi=300")
15-
.arg(format!("--root={}", dir))
1615
.arg(input)
1716
.arg(format!("{image_dir}/{{p}}.png"))
1817
.output()

src/main.rs

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -185,49 +185,14 @@ fn init_subscriber(level: tracing::Level) -> Result<(), SetGlobalDefaultError> {
185185
tracing::subscriber::set_global_default(subscriber)
186186
}
187187

188-
fn include_includes(input_dir: &Path, content: &str) -> String {
189-
let mut output = String::new();
190-
for line in content.lines() {
191-
if line.starts_with("#include") {
192-
let include = line.split_whitespace().nth(1).unwrap().trim_matches('"');
193-
let include_path = input_dir.join(include);
194-
tracing::debug!("Including file: {}", include_path.display());
195-
let content = std::fs::read_to_string(include_path).unwrap();
196-
for line in content.lines() {
197-
output.push_str(line);
198-
output.push('\n');
199-
}
200-
} else {
201-
output.push_str(line);
202-
output.push('\n');
203-
}
204-
}
205-
output
206-
}
207-
208-
/// Copy the Typst input file to the output directory.
209-
///
210-
/// This is necessary because Typst requires the input to be present in the
211-
/// project directory.
212-
fn copy_input_with_includes(dir: &str, input: &PathBuf) -> PathBuf {
213-
let output_path = Path::new(dir).join("input.typ");
214-
let content = std::fs::read_to_string(input).unwrap();
215-
let input_dir = Path::new(input).parent().unwrap();
216-
let content = include_includes(input_dir, &content);
217-
std::fs::write(&output_path, content).unwrap();
218-
219-
output_path
220-
}
221-
222188
pub(crate) async fn build(
223189
input: PathBuf,
224190
args: &Arguments,
225191
release: bool,
226192
audio_codec: Option<String>,
227193
) -> Vec<Slide> {
228194
let out_dir = &args.out_dir;
229-
let copied_input = copy_input_with_includes(out_dir, &input);
230-
let config = parse_config(&copied_input);
195+
let config = parse_config(&input);
231196

232197
let provider = config.provider.map(|p| provider_from_str(&p));
233198
let provider = provider.unwrap_or(Provider::DeepInfra);
@@ -243,11 +208,11 @@ pub(crate) async fn build(
243208
language_code: config.language_code.clone(),
244209
};
245210

246-
let slides = slide::slides(copied_input.to_str().unwrap());
211+
let slides = slide::slides(input.to_str().unwrap());
247212
if slides.is_empty() {
248213
panic!("No slides found in input file: {}", input.display());
249214
}
250-
image::generate_images(&copied_input, out_dir);
215+
image::generate_images(&input, out_dir);
251216
let audio_ext = tts_config
252217
.output_format
253218
.clone()

0 commit comments

Comments
 (0)