Add Makefile
This commit is contained in:
parent
07ca29aa55
commit
d23bbe6680
6 changed files with 55 additions and 50 deletions
7
docs/Cargo.lock
generated
7
docs/Cargo.lock
generated
|
@ -157,7 +157,6 @@ name = "docs"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"comrak 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"comrak 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"maud 0.20.0",
|
"maud 0.20.0",
|
||||||
"syntect 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syntect 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
@ -204,11 +203,6 @@ dependencies = [
|
||||||
"quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "indexmap"
|
|
||||||
version = "1.0.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
|
@ -688,7 +682,6 @@ dependencies = [
|
||||||
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
||||||
"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d"
|
"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d"
|
||||||
"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
|
"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
|
||||||
"checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d"
|
|
||||||
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
|
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
|
||||||
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
|
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
|
||||||
"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
|
"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
|
||||||
|
|
|
@ -12,6 +12,5 @@ edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
comrak = "*"
|
comrak = "*"
|
||||||
indexmap = "*"
|
|
||||||
maud = { path = "../maud" }
|
maud = { path = "../maud" }
|
||||||
syntect = "*"
|
syntect = "*"
|
||||||
|
|
18
docs/Makefile
Normal file
18
docs/Makefile
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
MARKDOWN_FILES := $(wildcard content/*.md)
|
||||||
|
HTML_FILES := $(patsubst content/%.md,site/%.html,$(MARKDOWN_FILES))
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: $(HTML_FILES) site/styles.css
|
||||||
|
|
||||||
|
target/debug/docs: $(wildcard src/*)
|
||||||
|
cargo build
|
||||||
|
|
||||||
|
site/%.html: content/%.md target/debug/docs
|
||||||
|
target/debug/docs build-page $< $@
|
||||||
|
|
||||||
|
site/styles.css: styles.css
|
||||||
|
cp $^ $@
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm -fr site
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
use comrak::{self, Arena, ComrakOptions};
|
use comrak::{self, Arena, ComrakOptions};
|
||||||
use comrak::nodes::{AstNode, NodeCodeBlock, NodeHeading, NodeHtmlBlock, NodeLink, NodeValue};
|
use comrak::nodes::{AstNode, NodeCodeBlock, NodeHeading, NodeHtmlBlock, NodeLink, NodeValue};
|
||||||
use indexmap::IndexMap;
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
@ -16,20 +16,30 @@ use syntect::html::highlighted_html_for_string;
|
||||||
|
|
||||||
mod views;
|
mod views;
|
||||||
|
|
||||||
const BOOK_FILES: &[&str] = &[
|
|
||||||
"index",
|
|
||||||
"getting-started",
|
|
||||||
"basic-syntax",
|
|
||||||
"dynamic-content",
|
|
||||||
"partials",
|
|
||||||
"control-structures",
|
|
||||||
"traits",
|
|
||||||
"web-frameworks",
|
|
||||||
"faq",
|
|
||||||
];
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
fs::create_dir_all("site")?;
|
let args = env::args().collect::<Vec<_>>();
|
||||||
|
if args.len() == 4 && &args[1] == "build-page" {
|
||||||
|
build_page(&args[2], &args[3])
|
||||||
|
} else {
|
||||||
|
Err("invalid arguments".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_page(input_path: &str, output_path: &str) -> Result<(), Box<dyn Error>> {
|
||||||
|
// TODO make this list dynamically generated
|
||||||
|
const NAV: &[(&str, Option<&str>)] = &[
|
||||||
|
("index", None),
|
||||||
|
("getting-started", Some("Getting started")),
|
||||||
|
("basic-syntax", Some("Basic syntax")),
|
||||||
|
("dynamic-content", Some("Dynamic content")),
|
||||||
|
("partials", Some("Partials")),
|
||||||
|
("control-structures", Some("Control structures")),
|
||||||
|
("traits", Some("Traits")),
|
||||||
|
("web-frameworks", Some("Web frameworks")),
|
||||||
|
("faq", Some("FAQ")),
|
||||||
|
];
|
||||||
|
|
||||||
|
fs::create_dir_all(Path::new(output_path).parent().unwrap())?;
|
||||||
|
|
||||||
let arena = Arena::new();
|
let arena = Arena::new();
|
||||||
let options = ComrakOptions {
|
let options = ComrakOptions {
|
||||||
|
@ -38,26 +48,10 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
..ComrakOptions::default()
|
..ComrakOptions::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut pages = IndexMap::<&str, _>::new();
|
let page = load_page(&arena, &options, input_path)?;
|
||||||
|
let markup = views::main(&options, input_path, page, &NAV);
|
||||||
|
|
||||||
for path in BOOK_FILES {
|
|
||||||
let mut input_path = Path::new("content").join(path);
|
|
||||||
input_path.set_extension("md");
|
|
||||||
|
|
||||||
let page = load_page(&arena, &options, &input_path)?;
|
|
||||||
|
|
||||||
pages.insert(path, page);
|
|
||||||
}
|
|
||||||
|
|
||||||
for path in pages.keys() {
|
|
||||||
let mut output_path = Path::new("site").join(path);
|
|
||||||
output_path.set_extension("html");
|
|
||||||
println!("{}", output_path.display());
|
|
||||||
let markup = views::main(&options, path, &pages);
|
|
||||||
fs::write(output_path, markup.into_string())?;
|
fs::write(output_path, markup.into_string())?;
|
||||||
}
|
|
||||||
|
|
||||||
fs::copy("styles.css", "site/styles.css")?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -70,7 +64,7 @@ struct Page<'a> {
|
||||||
fn load_page<'a>(
|
fn load_page<'a>(
|
||||||
arena: &'a Arena<AstNode<'a>>,
|
arena: &'a Arena<AstNode<'a>>,
|
||||||
options: &ComrakOptions,
|
options: &ComrakOptions,
|
||||||
path: &Path,
|
path: impl AsRef<Path>,
|
||||||
) -> io::Result<Page<'a>> {
|
) -> io::Result<Page<'a>> {
|
||||||
let buffer = fs::read_to_string(path)?;
|
let buffer = fs::read_to_string(path)?;
|
||||||
let content = comrak::parse_document(arena, &buffer, options);
|
let content = comrak::parse_document(arena, &buffer, options);
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use comrak::{self, ComrakOptions};
|
use comrak::{self, ComrakOptions};
|
||||||
use comrak::nodes::AstNode;
|
use comrak::nodes::AstNode;
|
||||||
use crate::Page;
|
use crate::Page;
|
||||||
use indexmap::IndexMap;
|
|
||||||
use maud::{DOCTYPE, Markup, Render, html};
|
use maud::{DOCTYPE, Markup, Render, html};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
@ -41,10 +40,10 @@ impl<'a> Render for ComrakText<'a> {
|
||||||
|
|
||||||
crate fn main<'a>(
|
crate fn main<'a>(
|
||||||
options: &'a ComrakOptions,
|
options: &'a ComrakOptions,
|
||||||
path: &str,
|
_path: &str, // TODO add nav indicator
|
||||||
pages: &IndexMap<&str, Page<'a>>,
|
page: Page<'a>,
|
||||||
|
nav: &[(&str, Option<&str>)],
|
||||||
) -> Markup {
|
) -> Markup {
|
||||||
let page = &pages[path];
|
|
||||||
html! {
|
html! {
|
||||||
(DOCTYPE)
|
(DOCTYPE)
|
||||||
meta charset="utf-8";
|
meta charset="utf-8";
|
||||||
|
@ -69,11 +68,11 @@ crate fn main<'a>(
|
||||||
|
|
||||||
nav {
|
nav {
|
||||||
ul {
|
ul {
|
||||||
@for (other_path, other_page) in pages {
|
@for (other_path, other_title) in nav {
|
||||||
@if let Some(title) = other_page.title {
|
@if let Some(title) = other_title {
|
||||||
li {
|
li {
|
||||||
a href={ (other_path) ".html" } {
|
a href={ (other_path) ".html" } {
|
||||||
(Comrak(title, options))
|
(title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,9 @@ python3 -m http.server -d site &
|
||||||
server_pid=$!
|
server_pid=$!
|
||||||
trap 'kill $server_pid' EXIT
|
trap 'kill $server_pid' EXIT
|
||||||
|
|
||||||
|
nproc=$(nproc || echo 4)
|
||||||
|
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
find . -name '*.rs' -o -name '*.md' -o -name '*.css' | entr -d cargo run
|
find . -name '*.rs' -o -name '*.md' -o -name '*.css' | entr -d make -j$nproc
|
||||||
done
|
done
|
||||||
|
|
Loading…
Add table
Reference in a new issue