Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added helper binary to regenerate READMEs #110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <nicolas@polomack.eu>"]
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]
31 changes: 31 additions & 0 deletions helpers/readme-render/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::env;
use std::fs;

use alexandrie_rendering::config::{SyntectConfig, SyntectState};

use serde::{Deserialize, Serialize};

#[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");
}