Skip to content

Commit

Permalink
Added helper binary to regenerate READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
Hirevo committed Mar 31, 2021
1 parent 457e217 commit b5e1689
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ members = [
"crates/alexandrie-storage",
"crates/alexandrie-rendering",
"helpers/syntect-dump",
"helpers/readme-render",
]
17 changes: 17 additions & 0 deletions helpers/readme-render/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "readme-render"
version = "0.1.0"
edition = "2018"
authors = ["Nicolas Polomack <[email protected]>"]
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]
26 changes: 26 additions & 0 deletions helpers/readme-render/src/main.rs
Original file line number Diff line number Diff line change
@@ -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");
}

0 comments on commit b5e1689

Please sign in to comment.