Created
May 6, 2020 10:57
-
-
Save makoConstruct/ca188df6fd7c6c4f626f04d2e2d3a01b to your computer and use it in GitHub Desktop.
the little ... script? (can it be a script if it's a compiled language? It felt like writing a script) that generates the html at aboutmako.makopool.com from a termpose tree of markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// extern crate tinytemplate; | |
extern crate comrak; | |
extern crate wood; | |
use wood::Wood; | |
use std::{path::Path, fs::{read_to_string, write}}; | |
use comrak::{markdown_to_html, ComrakOptions}; | |
fn indent_level(d:&Wood, indent:&mut String, out:&mut String){ | |
out.push_str(indent); | |
out.push_str("<div class=\"level\">\n"); | |
indent.push('\t'); | |
out.push_str(indent); | |
out.push_str(&markdown_to_html(d.initial_str(), &ComrakOptions::default())); | |
for sb in d.tail() { | |
indent_level(sb, indent, out); | |
} | |
indent.pop(); | |
out.push_str(indent); | |
out.push_str("</div>\n"); | |
} | |
fn main() { | |
let base_term = wood::parse_multiline_termpose(&read_to_string(Path::new("../mako\'s works.txt")).unwrap()).unwrap(); | |
let mut out = read_to_string(Path::new("../sidehead.html")).unwrap(); | |
out.push('\n'); | |
out.push_str("<body>\n"); | |
out.push_str("<div id=\"primary\">\n"); | |
out.push_str("<img id=\"dg\" src=\"dgabout.png\">\n"); | |
let mut indent = "".into(); | |
for sb in base_term.contents() { | |
indent_level(sb, &mut indent, &mut out); | |
} | |
out.push_str("</div>\n"); | |
out.push_str("</body>"); | |
write(Path::new("about.html"), &out).unwrap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment