diff --git a/README.md b/README.md index 22276dd..d63ab44 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ This tool aims to work somewhat similarly to _mkbook_, but is generally intended to be a more minimal alternative that is customized more towards my needs and desires than anything else. -Still very WIP, but it can convert `.md` files into fancy-looking `.html` files, demo it by running: `cargo run -- build demo` and then serving the `demo/book` directory. +Still very WIP, but it can convert `.md` files into fancy-looking `.html` files, demo it by building the `mkbook` book by running: `cargo run -- build -i docs-src -o docs` and then serving the `docs` directory. Alternatively, view these generated docs [here](https://hamaluik.github.io/mkbook/01-introduction.html). diff --git a/demo/.gitignore b/demo/.gitignore deleted file mode 100644 index 4e42a1b..0000000 --- a/demo/.gitignore +++ /dev/null @@ -1 +0,0 @@ -book/ \ No newline at end of file diff --git a/demo/src/01-introduction.md b/docs-src/01-introduction.md similarity index 100% rename from demo/src/01-introduction.md rename to docs-src/01-introduction.md diff --git a/demo/src/02-markdown.md b/docs-src/02-markdown.md similarity index 100% rename from demo/src/02-markdown.md rename to docs-src/02-markdown.md diff --git a/demo/src/03-frontmatter.md b/docs-src/03-frontmatter.md similarity index 100% rename from demo/src/03-frontmatter.md rename to docs-src/03-frontmatter.md diff --git a/demo/src/04-structure.md b/docs-src/04-structure.md similarity index 100% rename from demo/src/04-structure.md rename to docs-src/04-structure.md diff --git a/docs/01-introduction.html b/docs/01-introduction.html new file mode 100644 index 0000000..12939a7 --- /dev/null +++ b/docs/01-introduction.html @@ -0,0 +1,41 @@ + + + + + + Introduction + + + + + + +
+ + \ No newline at end of file diff --git a/docs/02-markdown.html b/docs/02-markdown.html new file mode 100644 index 0000000..a3dc513 --- /dev/null +++ b/docs/02-markdown.html @@ -0,0 +1,47 @@ + + + + + + Markdown + + + + + + +
+ + \ No newline at end of file diff --git a/docs/03-frontmatter.html b/docs/03-frontmatter.html new file mode 100644 index 0000000..0721a56 --- /dev/null +++ b/docs/03-frontmatter.html @@ -0,0 +1,68 @@ + + + + + + Front Matter + + + + + + +

Front Matter

+

Each .md file can optionally contain a header with metadata describing the document. If the header isn’t present, default values will be used which may look ugly.

+

To insert a header into a .md file, insert three dashes (---), followed by a new-line, followed by the front matter contents, followed by a newline, then another three dashes and a new-line. The metadata is in the TOML format, so for example the front-matter (and first line) for this file looks like:

+
+---
+title = "Front Matter"
+---
+
+# Front Matter
+
+Each `.md` file can optionally contain a header with metadata describing the document. If the header isn't present, default values will be used which may look ugly.
+
+

Supported Keys

+

The list of supported keys is subject to change, but for now it is as follows:

+
+

title

+
+
+

A human-readable title for the document

+
+
+
+ + \ No newline at end of file diff --git a/docs/04-structure.html b/docs/04-structure.html new file mode 100644 index 0000000..fb53eac --- /dev/null +++ b/docs/04-structure.html @@ -0,0 +1,41 @@ + + + + + + Structure + + + + + + +
+ + \ No newline at end of file diff --git a/docs/favicon.ico b/docs/favicon.ico new file mode 100644 index 0000000..5e15baa Binary files /dev/null and b/docs/favicon.ico differ diff --git a/docs/icons.svg b/docs/icons.svg new file mode 100644 index 0000000..d50227b --- /dev/null +++ b/docs/icons.svg @@ -0,0 +1,12 @@ + diff --git a/docs/style.css b/docs/style.css new file mode 100644 index 0000000..32bb058 --- /dev/null +++ b/docs/style.css @@ -0,0 +1 @@ +@import url("https://fonts.googleapis.com/css?family=Crimson+Pro|Poppins:700|Source+Code+Pro&display=swap");body{margin:0;line-height:1.5;font-size:14pt;color:#222222;background:#eeeeee;padding:0;font-family:"Crimson Pro","Georgia",Georgia,"Times New Roman",Times,serif}h1,h2,h3{margin-top:0;line-height:1.2;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif}a{color:#222222;text-decoration:underline}a:hover{color:#8a2888;text-decoration:none}figure{display:block;text-align:center;overflow-x:auto}figure img,figure video{max-width:100%}figure figcaption{display:block;font-size:0.75em;text-align:center}code{margin:0 2px;padding:0 2px;border:1px solid #4c566a;border-radius:3px;word-break:break-all;font-family:"Source Code Pro","Courier New",Courier,monospace;font-size:0.75em}pre{overflow-x:auto;font-family:"Source Code Pro","Courier New",Courier,monospace;padding:0}dl{display:grid;grid-template-columns:auto 1fr}dl dt{font-weight:700;margin:0;padding:0.5em;border-right:1px solid #dddddd}dl dd{margin:0;padding:0.5em}dl dt p,dl dd p{margin:0}html,body{width:100%;min-height:100vh}body{display:grid;grid-template-columns:auto 1fr;grid-template-rows:1fr;justify-items:stretch;align-items:stretch}body nav.big{background:#2c2c38;padding:1em;display:flex;flex-direction:column}body nav.big a{width:100%;font-size:1.5em;text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin:0 0 0.25em 0;color:#5babd1}body nav.big a:hover{color:#cf5ccd}body nav.big a.current{color:#cf5ccd}body nav.big a.current:hover{color:#fefefe}body nav.small{display:none;width:100%;align-items:center;justify-content:space-between;background:#2c2c38;padding:0}body nav.small>*{margin:0.5em}body nav.small a{text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#5babd1}body nav.small a:hover{color:#cf5ccd}body nav.small span.title{text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#fefefe}body nav.small span.placeholder{width:1em;height:1em}body article{padding:1em 2em 0 2em;max-width:38em;min-width:0;min-height:0}body article>*{max-width:100%}@media screen and (max-width: 768px){body{grid-template-columns:1fr;grid-template-rows:auto 1fr}body nav.big{display:none}body nav.small{display:flex}body article{padding:1em 0.5em 0 0.5em}}span.icon{display:flex;align-items:center}[class^="icon-"],[class*=" icon-"]{display:inline-block;width:1em;height:1em;stroke-width:0;stroke:currentColor;fill:currentColor}.icon-arrow-left{width:0.875em}.icon-arrow-right{width:0.875em}@media (prefers-color-scheme: dark){body{background-color:#222222;color:#eeeeee}a{color:#eeeeee}a:hover{color:#5babd1}nav{background:#18181d}img{filter:grayscale(30%)}}@media print{body{background:#ffffff;color:#000000}a{color:#000000;text-decoration:underline}h2,h3{break-after:avoid-page}figure{break-inside:avoid}p{orphans:2;widows:2}*{overflow:hidden}nav{display:none}body{display:block}} diff --git a/src/cli.rs b/src/cli.rs index b7ca8d0..a3a3122 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -16,8 +16,17 @@ pub fn build_cli() -> App<'static, 'static> { ) .subcommand(SubCommand::with_name("build") .about("build the book") - .arg(Arg::with_name("directory") - .help("an optional directory to build the book in (defaults to the CWD)") + .arg(Arg::with_name("in") + .short("i") + .long("in") + .default_value("src") + .help("an optional directory to take the book sources from") + ) + .arg(Arg::with_name("out") + .short("o") + .long("out") + .default_value("book") + .help("an optional directory to render the contents into") ) ) } diff --git a/src/main.rs b/src/main.rs index ad8961b..789c8e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -177,15 +177,11 @@ fn main() -> Result<(), Box> { unimplemented!() } else if let Some(submatches) = matches.subcommand_matches("build") { - let prefix = if let Some(directory) = submatches.value_of("directory") { - PathBuf::from(directory) - } - else { - PathBuf::from(".") - }; + let src = submatches.value_of("in").expect("in value"); + let dest = submatches.value_of("out").expect("out value"); - let src = prefix.join("src"); - let dest = prefix.join("book"); + let src = PathBuf::from(src); + let dest = PathBuf::from(dest); std::fs::create_dir_all(&dest)?; // load all our chapters @@ -202,7 +198,7 @@ fn main() -> Result<(), Box> { let (front, _) = extract_frontmatter(&contents)?; let front = front.unwrap_or_default().into_front(name); chapters.push(models::chapter::Chapter { - url: format!("/{}.html", name), + url: format!("{}.html", name), title: front.title, }); } @@ -226,7 +222,7 @@ fn main() -> Result<(), Box> { let (front, contents) = extract_frontmatter(&contents)?; let front = front.unwrap_or_default().into_front(name); let contents = format_markdown(&contents)?; - format_page(front, &chapters, &format!("/{}.html", name), &contents, outfile)?; + format_page(front, &chapters, &format!("{}.html", name), &contents, outfile)?; println!("Rendered `{}` into `{}`", path.display(), out.display()); } diff --git a/templates/page.html b/templates/page.html index 19af53e..d419bda 100644 --- a/templates/page.html +++ b/templates/page.html @@ -4,8 +4,8 @@ {{ title }} - - + +