From b5e168930598e1e4e178f16d3ffb9ca983e45353 Mon Sep 17 00:00:00 2001 From: Nicolas Polomack Date: Wed, 31 Mar 2021 18:42:57 +0200 Subject: [PATCH] Added helper binary to regenerate READMEs --- Cargo.lock | 9 +++++++++ Cargo.toml | 1 + helpers/readme-render/Cargo.toml | 17 +++++++++++++++++ helpers/readme-render/src/main.rs | 26 ++++++++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 helpers/readme-render/Cargo.toml create mode 100644 helpers/readme-render/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 642e1beb..65e599ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2206,6 +2206,15 @@ dependencies = [ "rand_core", ] +[[package]] +name = "readme-render" +version = "0.1.0" +dependencies = [ + "alexandrie-rendering", + "serde", + "toml", +] + [[package]] name = "redox_syscall" version = "0.1.57" diff --git a/Cargo.toml b/Cargo.toml index dbdead7f..34d0ddcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,5 @@ members = [ "crates/alexandrie-storage", "crates/alexandrie-rendering", "helpers/syntect-dump", + "helpers/readme-render", ] diff --git a/helpers/readme-render/Cargo.toml b/helpers/readme-render/Cargo.toml new file mode 100644 index 00000000..a5917c35 --- /dev/null +++ b/helpers/readme-render/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "readme-render" +version = "0.1.0" +edition = "2018" +authors = ["Nicolas Polomack "] +description = "A simple helper to generate syntect's binary dumps for Alexandrie" +repository = "https://github.com/Hirevo/alexandrie" +documentation = "https://crates.polomack.eu/docs/alexandrie" +license = "MIT OR Apache-2.0" +publish = false + +[dependencies] +alexandrie-rendering = { path = "../../crates/alexandrie-rendering", version = "0.1.0" } +serde = { version = "1.0.124", features = ["derive"] } +toml = "0.5.8" + +[features] diff --git a/helpers/readme-render/src/main.rs b/helpers/readme-render/src/main.rs new file mode 100644 index 00000000..ba22b183 --- /dev/null +++ b/helpers/readme-render/src/main.rs @@ -0,0 +1,26 @@ +use std::fs; +use std::env; + +use alexandrie_rendering::config::{SyntectConfig, SyntectState}; + +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] +pub struct Config { + /// The syntax-highlighting configuration. + pub syntect: SyntectConfig, +} + +fn main() { + let readme_path = env::args().skip(1).next().expect("could not find a command-line argument"); + + let contents = fs::read("alexandrie.toml").expect("could not open configuration file `alexandrie.toml`"); + let config: Config = toml::from_slice(contents.as_slice()).expect("could not parse configuration file"); + + let state = SyntectState::from(config.syntect); + + let contents = fs::read_to_string(readme_path).expect("could not open README file"); + let rendered = alexandrie_rendering::render_readme(&state, &contents); + + fs::write("output.html", &rendered).expect("could not write rendered HTML output"); +}