Implement MVP Typst embedding

finchie
Oct 24, 2023, 4:28 PM
BSJYWOYSJRERQ45AD7RN3364RYQ5P3IM76S67262VLFZPFO3B5JQC

Dependencies

Change contents

  • edit in src/main.rs at line 79
    [5.1766]
    [6.371]
    }
    fn content(state: &AppState) -> impl View<AppState> + ViewMarker {
    el::div(include_str!("../dist/.stage/docs/test.html"))
  • replacement in src/main.rs at line 95
    [2.114][2.114:161]()
    el::div(()).attr("id", "content"),
    [2.114]
    [2.161]
    el::div(content(&state)).attr("id", "content"),
  • file addition: docs (d--r------)
    [7.1]
  • file addition: test.typ (----------)
    [0.207]
    = Hello
    Hello from typst!
  • file addition: build.rs (----------)
    [7.1]
    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 time
    fn 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 directory
    std::fs::create_dir_all(TRUNK_STAGING_DIRECTORY).unwrap();
    // Build all the files
    let 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 correctly
    let remainder = if parent != prefix {
    assert!(parent.starts_with(&prefix));
    parent.strip_prefix(&prefix).unwrap().to_path_buf()
    } else {
    PathBuf::new()
    };
    // Create the appropriate directory layout
    let mut output_path = staging_dir
    .join(remainder)
    .join(file.path().file_name().unwrap());
    // Our input is .typ, but output is .html
    output_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");
    }
    }
  • edit in Cargo.toml at line 15
    [3.1474]
    [build-dependencies]
    walkdir = "2.4.0"
  • edit in Cargo.lock at line 209
    [5.2363]
    [3.4315]
    "walkdir",
  • edit in Cargo.lock at line 252
    [3.5214]
    [3.5214]
    name = "same-file"
    version = "1.0.6"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
    dependencies = [
    "winapi-util",
    ]
    [[package]]
  • edit in Cargo.lock at line 391
    [8.3866]
    [8.3866]
    [[package]]
    name = "walkdir"
    version = "2.4.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee"
    dependencies = [
    "same-file",
    "winapi-util",
    ]
  • edit in Cargo.lock at line 467
    [3.7968]
    [8.3880]
    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]]