This is a halfway-done implementation at best, my plan from here is to convert Typst to Xilem (Rust) code, which will hopefully be much neater. Then I have to find a way to parameterize the Typst text based on the Xilem state, so when someone changes a number in their input, the documentation changes to match.
BSJYWOYSJRERQ45AD7RN3364RYQ5P3IM76S67262VLFZPFO3B5JQC A4E5KLI2CEHJLO6WUME2VIXPK4C2DXHCBVEK2TJTLHGCRCZ2ZC7QC REI53XR4WDH5EKLTXTFVTOVWCCFRWTFH4GQS6DSNM5LSRFTX7HJQC JFJVY57RWKT6YJ62MWWOHXSLASLWPORFUGF67TVTW4FW7XBZEAUQC C73UJ7ZYG4EE3YTK3N66GXPNWJHEBSRE4PDQBWMN6SKQ3U6ZYKXAC G4Q265KPMPG7EZNDBYANU2MSLVDGXRTEQMFWRCNJ3HGEL7TLCI4AC BMG4FSHNV54VXDHNUVGZOMXQJWLFSUF3M5NCN7GJETNIF3QTHELQC = HelloHello from typst!
use std::{ffi::OsStr, path::PathBuf, process::Command};use walkdir::WalkDir;const TRUNK_STAGING_DIRECTORY: &str = "dist/.stage";const DOCS_SOURCE: &str = "docs";// TODO: avoid re-building docs every timefn main() {// Recursively find all .typ (typst) files within `docs/`let typst_files = WalkDir::new(DOCS_SOURCE).into_iter()// Remove inaccessible directories.filter_map(|possible_entry| possible_entry.ok())// Only find files.filter(|entry| entry.path().is_file())// Only find typst (.typ) files.filter(|entry| entry.path().extension() == Some(OsStr::new("typ")));// Set up the staging directorystd::fs::create_dir_all(TRUNK_STAGING_DIRECTORY).unwrap();// Build all the fileslet prefix = PathBuf::from(DOCS_SOURCE);let staging_dir = PathBuf::from(TRUNK_STAGING_DIRECTORY).join(DOCS_SOURCE);for file in typst_files {let parent = file.path().parent().unwrap();// Handle nested directories correctlylet remainder = if parent != prefix {assert!(parent.starts_with(&prefix));parent.strip_prefix(&prefix).unwrap().to_path_buf()} else {PathBuf::new()};// Create the appropriate directory layoutlet mut output_path = staging_dir.join(remainder).join(file.path().file_name().unwrap());// Our input is .typ, but output is .htmloutput_path.set_extension("html");std::fs::create_dir_all(output_path.parent().unwrap()).unwrap();Command::new("pandoc").args([file.path().to_str().unwrap(),"-o",output_path.to_str().unwrap(),]).status().expect("Error running pandoc. Check if it's installed");}}
[build-dependencies]walkdir = "2.4.0"
name = "winapi"version = "0.3.9"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"dependencies = ["winapi-i686-pc-windows-gnu","winapi-x86_64-pc-windows-gnu",][[package]]name = "winapi-i686-pc-windows-gnu"version = "0.4.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"[[package]]name = "winapi-util"version = "0.1.6"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"dependencies = ["winapi",][[package]]name = "winapi-x86_64-pc-windows-gnu"version = "0.4.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"[[package]]