From c8a477a4e402f4e9fc4db86893ef65276ae78aa0 Mon Sep 17 00:00:00 2001 From: Kenton Hamaluik Date: Sun, 8 Dec 2019 23:28:43 -0700 Subject: [PATCH] refactored file placement on html, added assets on latex --- docs-src/04-structure.md | 2 +- .../index.html => 01-command-line.html} | 49 +++-- docs/01-introduction/index.html | 206 ------------------ docs/02-markdown/01-commonmark.html | 13 +- docs/02-markdown/02-syntax-highlighting.html | 13 +- docs/02-markdown/03-plantuml-diagrams.html | 13 +- docs/02-markdown/04-katex-formulas.html | 13 +- docs/02-markdown/05-images.html | 13 +- docs/02-markdown/06-tables.html | 13 +- docs/02-markdown/07-task-lists.html | 17 +- docs/02-markdown/index.html | 15 +- .../index.html => 03-frontmatter.html} | 53 ++--- .../index.html => 04-structure.html} | 55 ++--- .../index.html => 05-customization.html} | 53 ++--- .../index.html => 06-how-it-works.html} | 45 ++-- docs/index.html | 14 +- docs/style.css | 2 +- src/html.rs | 24 +- src/latex.rs | 45 +++- src/main.rs | 2 +- style/layout.scss | 8 + templates/book.tex | 11 +- templates/page.html | 29 +-- 23 files changed, 293 insertions(+), 415 deletions(-) rename docs/{01-command-line/index.html => 01-command-line.html} (87%) delete mode 100644 docs/01-introduction/index.html rename docs/{03-frontmatter/index.html => 03-frontmatter.html} (70%) rename docs/{04-structure/index.html => 04-structure.html} (79%) rename docs/{05-customization/index.html => 05-customization.html} (59%) rename docs/{06-how-it-works/index.html => 06-how-it-works.html} (77%) diff --git a/docs-src/04-structure.md b/docs-src/04-structure.md index b85e02c..562cfa8 100644 --- a/docs-src/04-structure.md +++ b/docs-src/04-structure.md @@ -65,7 +65,7 @@ Any files in the `src` directory which are not included in `.gitignore` and do n ![chapter-six](book-chapter-six-5834.jpg "Photo by Kaboompics.com from Pexels") ``` -![chapter-six](../book-chapter-six-5834.jpg "Photo by Kaboompics.com from Pexels") +![chapter-six](book-chapter-six-5834.jpg "Photo by Kaboompics.com from Pexels") # Documents diff --git a/docs/01-command-line/index.html b/docs/01-command-line.html similarity index 87% rename from docs/01-command-line/index.html rename to docs/01-command-line.html index 3e5076a..e13236c 100644 --- a/docs/01-command-line/index.html +++ b/docs/01-command-line.html @@ -4,70 +4,70 @@ The mkbook Book | Command-line Interface - - + + - + - +
+

Command-line Interface

mkbook may be installed using Cargo (cargo install --force --path . in the mkbook repo directory), and after that it presents a command-line interface:

 $ mkbook
@@ -202,11 +203,11 @@
             
             
             
- + Next chapter: “Markdown” - + diff --git a/docs/01-introduction/index.html b/docs/01-introduction/index.html deleted file mode 100644 index 4c9d557..0000000 --- a/docs/01-introduction/index.html +++ /dev/null @@ -1,206 +0,0 @@ - - - - - - The mkbook Book | Introduction - - - - - - - - - - - - - - -
-

Introduction

-

mkbook is my simpler alternative to mdbook which is a great tool, but for which I really dislike some of the decisions they took, such as relying on javascript for highlighting and navigation, and including a lot of bells and whistles such as javascript-based search.

-

This tool aims to work somewhat similarly to mdbook, but is generally intended to be a more minimal alternative that is customized more towards my needs and desires than anything else.

-

If you’re not familiar with mdbook, mkbook is a tool to convert a collection of Markdown files into a static website / book which can be published online. It was created to help me write documentation with minimum fuss while presenting it in an easy-to-consume manner.

-

Command-line Interface

-

mkbook may be installed using Cargo (cargo install --force --path . in the mkbook repo directory), and after that it presents a command-line interface:

-
-$ mkbook
-mkbook 0.3.0
-Kenton Hamaluik <kenton@hamaluik.ca>
-
-
-USAGE:
-    mkbook [SUBCOMMAND]
-
-FLAGS:
-    -h, --help       
-            Prints help information
-
-    -V, --version    
-            Prints version information
-
-
-SUBCOMMANDS:
-    build    build the book
-    help     Prints this message or the help of the given subcommand(s)
-    init     initialize a mkbook directory tree
-    watch    build the book and continually rebuild whenever the source changes
-
-

The Init Command

-

The init command is a tool to help you get started, and will create an initial README.md file and a stub of your first chapter.

-
-$ mkbook init --help
-mkbook-init 
-initialize a mkbook directory tree
-
-USAGE:
-    mkbook init [OPTIONS]
-
-FLAGS:
-    -h, --help       Prints help information
-    -V, --version    Prints version information
-
-OPTIONS:
-    -d, --directory <directory>    an optional directory to initialize into [default: src]
-
-

The Build Command

-

The build command is the primary command for mkbook, and is responsible for taking the .md files and building the resulting website.

-
-$ mkbook build --help
-mkbook-build 
-build the book
-
-USAGE:
-    mkbook build [OPTIONS]
-
-FLAGS:
-    -h, --help       Prints help information
-    -V, --version    Prints version information
-
-OPTIONS:
-    -i, --in <in>      an optional directory to take the book sources from [default: src]
-    -o, --out <out>    an optional directory to render the contents into [default: book]
-
-

The Watch Command

-

The watch command is basically the same as the build command, however after building it continues to monitor the source directory and if any changes are made (a file is saved, renamed, removed, created, etc), the entire book is re-built. In the future, this will hopefully be smarter but for now it just the whole thing at once. Stop watching using Ctrl+C or sending SIGINT.

-
-$ mkbook build --help
-mkbook-watch 
-build the book and continually rebuild whenever the source changes
-
-USAGE:
-    mkbook watch [OPTIONS]
-
-FLAGS:
-    -h, --help       Prints help information
-    -V, --version    Prints version information
-
-OPTIONS:
-    -i, --in <in>      an optional directory to take the book sources from [default: src]
-    -o, --out <out>    an optional directory to render the contents into [default: book]
-
- - - - - -

© 2019 Kenton Hamaluik

-
- - - \ No newline at end of file diff --git a/docs/02-markdown/01-commonmark.html b/docs/02-markdown/01-commonmark.html index c8cfdab..587c87b 100644 --- a/docs/02-markdown/01-commonmark.html +++ b/docs/02-markdown/01-commonmark.html @@ -12,7 +12,7 @@ - + @@ -24,7 +24,7 @@
  1. - Command-line Interface + Command-line Interface
  2. @@ -52,22 +52,22 @@
  3. - Front Matter + Front Matter
  4. - Structure + Structure
  5. - Customization + Customization
  6. - How it Works + How it Works
  7. @@ -111,6 +111,7 @@
    +

    CommonMark

    mkbook nominally utilizes CommonMark with some GFM extensions through the use of the comrak crate. In using comrak, a specific set of options are used, which are listed here:

     let options: ComrakOptions = ComrakOptions {
    diff --git a/docs/02-markdown/02-syntax-highlighting.html b/docs/02-markdown/02-syntax-highlighting.html
    index ce6a679..d636c5b 100644
    --- a/docs/02-markdown/02-syntax-highlighting.html
    +++ b/docs/02-markdown/02-syntax-highlighting.html
    @@ -12,7 +12,7 @@
             
             
             
    -        
    +        
             
         
         
    @@ -24,7 +24,7 @@
                 
    1. - Command-line Interface + Command-line Interface
    2. @@ -52,22 +52,22 @@
    3. - Front Matter + Front Matter
    4. - Structure + Structure
    5. - Customization + Customization
    6. - How it Works + How it Works
    7. @@ -111,6 +111,7 @@
      +

      Syntax Highlighting

      GFM syntax highlighting is also available by using fenced code tags with a label denoting the language, as such:

       ```c++
      diff --git a/docs/02-markdown/03-plantuml-diagrams.html b/docs/02-markdown/03-plantuml-diagrams.html
      index 9285c83..ce79d27 100644
      --- a/docs/02-markdown/03-plantuml-diagrams.html
      +++ b/docs/02-markdown/03-plantuml-diagrams.html
      @@ -12,7 +12,7 @@
               
               
               
      -        
      +        
               
           
           
      @@ -24,7 +24,7 @@
                   
      1. - Command-line Interface + Command-line Interface
      2. @@ -52,22 +52,22 @@
      3. - Front Matter + Front Matter
      4. - Structure + Structure
      5. - Customization + Customization
      6. - How it Works + How it Works
      7. @@ -111,6 +111,7 @@
        +

        PlantUML Diagrams

        If you have PlantUML installed and available on your path, mkbook will try to render any code blocks with a language tag of plantuml as inline SVG images.

        For example:

        diff --git a/docs/02-markdown/04-katex-formulas.html b/docs/02-markdown/04-katex-formulas.html
        index 03bc47f..5027743 100644
        --- a/docs/02-markdown/04-katex-formulas.html
        +++ b/docs/02-markdown/04-katex-formulas.html
        @@ -12,7 +12,7 @@
                 
                 
                 
        -        
        +        
                 
             
             
        @@ -24,7 +24,7 @@
                     
        1. - Command-line Interface + Command-line Interface
        2. @@ -52,22 +52,22 @@
        3. - Front Matter + Front Matter
        4. - Structure + Structure
        5. - Customization + Customization
        6. - How it Works + How it Works
        7. @@ -111,6 +111,7 @@
          +

          KaTeX (Math) Formulas

          If you have KaTeX installed and available on your path, mkbook will try to render any code blocks with a language tag of katex as inline math blocks.

          For example:

          diff --git a/docs/02-markdown/05-images.html b/docs/02-markdown/05-images.html
          index cdb90b1..95d88b0 100644
          --- a/docs/02-markdown/05-images.html
          +++ b/docs/02-markdown/05-images.html
          @@ -12,7 +12,7 @@
                   
                   
                   
          -        
          +        
                   
               
               
          @@ -24,7 +24,7 @@
                       
          1. - Command-line Interface + Command-line Interface
          2. @@ -52,22 +52,22 @@
          3. - Front Matter + Front Matter
          4. - Structure + Structure
          5. - Customization + Customization
          6. - How it Works + How it Works
          7. @@ -111,6 +111,7 @@
            +

            Images

            To include an image, use the standard markdown format:

             ![alt](url "title")
            diff --git a/docs/02-markdown/06-tables.html b/docs/02-markdown/06-tables.html
            index 662e4d0..5acba4e 100644
            --- a/docs/02-markdown/06-tables.html
            +++ b/docs/02-markdown/06-tables.html
            @@ -12,7 +12,7 @@
                     
                     
                     
            -        
            +        
                     
                 
                 
            @@ -24,7 +24,7 @@
                         
            1. - Command-line Interface + Command-line Interface
            2. @@ -52,22 +52,22 @@
            3. - Front Matter + Front Matter
            4. - Structure + Structure
            5. - Customization + Customization
            6. - How it Works + How it Works
            7. @@ -111,6 +111,7 @@
              +

              Tables

              Tables are created using the pipe syntax, for example the following:

               | Tables        | Are           | Cool  |
              diff --git a/docs/02-markdown/07-task-lists.html b/docs/02-markdown/07-task-lists.html
              index d3397b7..4f5527d 100644
              --- a/docs/02-markdown/07-task-lists.html
              +++ b/docs/02-markdown/07-task-lists.html
              @@ -12,7 +12,7 @@
                       
                       
                       
              -        
              +        
                       
                   
                   
              @@ -24,7 +24,7 @@
                           
              1. - Command-line Interface + Command-line Interface
              2. @@ -52,22 +52,22 @@
              3. - Front Matter + Front Matter
              4. - Structure + Structure
              5. - Customization + Customization
              6. - How it Works + How it Works
              7. @@ -100,7 +100,7 @@ - + @@ -111,6 +111,7 @@
                +

                Task Lists

                You can also use GFM-style task lists to indicate a TODO list:

                • a task list item
                • @@ -123,7 +124,7 @@
                  - + Next chapter: “Front Matter” diff --git a/docs/02-markdown/index.html b/docs/02-markdown/index.html index e55728e..ee3ec07 100644 --- a/docs/02-markdown/index.html +++ b/docs/02-markdown/index.html @@ -12,7 +12,7 @@ - + @@ -24,7 +24,7 @@
                  1. - Command-line Interface + Command-line Interface
                  2. @@ -52,22 +52,22 @@
                  3. - Front Matter + Front Matter
                  4. - Structure + Structure
                  5. - Customization + Customization
                  6. - How it Works + How it Works
                  7. @@ -84,7 +84,7 @@ - + @@ -111,6 +111,7 @@
                    +

                    Markdown

                    mkbook relies pretty extensively on Markdown for its ease of use. If you’re not familiar with Markdown, it is a simple markup language that is design to be easy to read and write in plain text, and then (relatively) easy for a computer to convert into other formats such as HTML or LaTeX.

                    The above paragraph looks like this:

                    diff --git a/docs/03-frontmatter/index.html b/docs/03-frontmatter.html
                    similarity index 70%
                    rename from docs/03-frontmatter/index.html
                    rename to docs/03-frontmatter.html
                    index ad71451..6a011bc 100644
                    --- a/docs/03-frontmatter/index.html
                    +++ b/docs/03-frontmatter.html
                    @@ -4,70 +4,70 @@
                             
                             
                             The mkbook Book | Front Matter
                    -        
                    -        
                    +        
                    +        
                             
                             
                             
                    -        
                    +        
                             
                             
                    -        
                    +        
                             
                         
                         
                             
                             
                             
                    +

                    Front Matter

                    Each .md file can optionally contain a header with metadata describing the document. If the header isn’t present, or if any keys are missing, default values will be used.

                    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 a file could look like this:

                    @@ -153,11 +154,11 @@
                                 
                                 
                                 
                    - + Next chapter: “Structure” - + diff --git a/docs/04-structure/index.html b/docs/04-structure.html similarity index 79% rename from docs/04-structure/index.html rename to docs/04-structure.html index b819b34..2d6b375 100644 --- a/docs/04-structure/index.html +++ b/docs/04-structure.html @@ -4,70 +4,70 @@ The mkbook Book | Structure - - + + - + - +
                    +

                    Structure

                    mkbook follows a fairly simple directory structure for now, with a README.md file declaring the book’s metadata, and .md files defining each chapter of the book.

                    README.md

                    mkbook generally requires a README.md file to reside in your source directory. This file is responsible for defining the metadata associated with your book:

                    @@ -176,7 +177,7 @@
                     ![chapter-six](book-chapter-six-5834.jpg "Photo by Kaboompics.com from Pexels")
                     
                    -
                    chapter-six
                    Photo by Kaboompics.com from Pexels
                    +
                    chapter-six
                    Photo by Kaboompics.com from Pexels

                    Documents

                    mkbook works on mostly a flat directory structure, however one level of sub-directories are supported in order to create sections within chapters. Files that don’t end in a .md extension are completely ignored. Each .md file in the root source directly is it’s own chapter. To create chapters with sub-sections, create a sub-directory in the root directory and then create a README.md file, which will become the root of the chapter, with all .md files in the sub-directory becoming sections in the chapter. The title in the README.md file’s frontmatter will be used as the name of the chapter.

                    The order of the book is based on the alphabetical order of the file names (actually it’s based on Rust’s implementation of PartialOrd for str). Thus, it is recommended to lay out your book chapters with manual numbering of the file names, as such:

                    @@ -197,11 +198,11 @@
                    - + Next chapter: “Customization” - + diff --git a/docs/05-customization/index.html b/docs/05-customization.html similarity index 59% rename from docs/05-customization/index.html rename to docs/05-customization.html index e14857f..e47fb68 100644 --- a/docs/05-customization/index.html +++ b/docs/05-customization.html @@ -4,70 +4,70 @@ The mkbook Book | Customization - - + + - + - +
                    +

                    Customization

                    There isn’t any way to customize the templates nor the CSS yet, though I will investigate this if the need arises. This is because both the templates and CSS are currently compiled at compile-time instead of run-time.

                    - + Next chapter: “How it Works” - + diff --git a/docs/06-how-it-works/index.html b/docs/06-how-it-works.html similarity index 77% rename from docs/06-how-it-works/index.html rename to docs/06-how-it-works.html index 433e8a3..cf1b767 100644 --- a/docs/06-how-it-works/index.html +++ b/docs/06-how-it-works.html @@ -4,70 +4,70 @@ The mkbook Book | How it Works - - + + - + - +
                    +

                    How it Works

                    mkbook generates a completely static, javascript-free website from a series of Markdown files. All of the layout and styling is controlled purely by hand-crafted CSS specific to this book’s purpose.

                    Assets

                    mkbook currently bundles two assets which get written into the book directory: favicon.ico, and icons.svg. favicon.ico is the Font Awesome 5 book icon, and icons.svg contains 3 Font Awesome 5 arrow icons: arrow-left, arrow-right, and arrow-up which are used for navigation. These files are compiled into the mkbook binary using the include_bytes! macro, and written to the output folder on each build.

                    diff --git a/docs/index.html b/docs/index.html index 3c341f6..109a0ab 100644 --- a/docs/index.html +++ b/docs/index.html @@ -15,14 +15,14 @@ <p>If you’re not familiar with <em>mdbook</em>, <em>mkbook</em> is a tool to convert a collection of <a href="https://commonmark.org/">Markdown</a> files into a static website / book which can be published online. It was created to help me write documentation with minimum fuss while presenting it in an easy-to-consume manner.</p> " /> - +

                    The mkbook Book

                    by Kenton Hamaluik

                    - +

                    mkbook is my simpler alternative to mdbook which is a great tool, however I really dislike some of the decisions they took—such as relying on javascript for highlighting and navigation and including a lot of bells and whistles such as javascript-based search.

                    @@ -35,7 +35,7 @@
                    1. - Command-line Interface + Command-line Interface
                    2. @@ -63,22 +63,22 @@
                    3. - Front Matter + Front Matter
                    4. - Structure + Structure
                    5. - Customization + Customization
                    6. - How it Works + How it Works
                    7. diff --git a/docs/style.css b/docs/style.css index 4b72bb0..29c2f77 100644 --- a/docs/style.css +++ b/docs/style.css @@ -1 +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}img,svg,video{max-width:100%}figure{display:block;text-align:center;overflow-x:auto;margin:0 0 1em}figure figcaption{display:block;font-size:0.9rem;text-align:center}code,kbd{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.75rem}kbd{color:#222222;background:#eeeeee;box-shadow:0px 2px 4px rgba(0,0,0,0.5)}pre{overflow-x:auto;font-family:"Source Code Pro","Courier New",Courier,monospace;padding:0.5rem}dl{display:grid;grid-template-columns:auto auto}dl dt{font-weight:700;margin:0;padding:0 0.5rem 0.25rem;border-right:1px solid #dddddd;text-align:right}dl dd{margin:0;padding:0 0.5rem 0.25rem}dl dt p,dl dd p{margin:0}p{margin-top:0}footer{color:#444444}footer p{margin-right:0.5rem}table{margin:0 auto;border-collapse:collapse;border-spacing:0.5rem}table th{border-bottom:1px solid #eee}table th,table td{vertical-align:top}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;position:relative}body nav.big{background:#2c2c38;padding:0.5rem 1rem 1rem;max-width:15rem;position:sticky;display:flex;flex-direction:column}body nav.big header{margin:0 0 1rem;display:flex;flex-direction:column;align-items:stretch;border-bottom:2px solid #888888}body nav.big header h1{font-size:1.5rem;font-weight:700;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0;text-align:left;color:#eeeeee}body nav.big header h1 a{color:#eeeeee;text-decoration:none}body nav.big header h1 a:hover{color:#cf5ccd}body nav.big header h2{font-size:1rem;font-weight:600;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0;text-align:right;color:#eeeeee}body nav.big ol{margin:0 2rem;padding:0}body nav.big ol li{width:100%;font-size:1.25rem;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#eeeeee}body nav.big ol li a{text-decoration:none;margin:0 0 0.25rem 0;color:#5babd1}body nav.big ol li a:hover{color:#cf5ccd}body nav.big ol li a.current{color:#cf5ccd}body nav.big ol li a.current:hover{color:#fefefe}body nav.big ol li ol{margin:0 0 0 1rem}body nav.small{display:none;width:100%;align-items:center;justify-content:space-between;background:#2c2c38;padding:0;position:sticky;top:0;box-shadow:0px 2px 4px rgba(0,0,0,0.25)}body nav.small>*{margin:0.5rem}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{display:inline-flex;align-items:center}body nav.small span>*{margin-right:0.5rem}body nav.small span>*:last-child{margin-right:0}body nav.small span.title{text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#fefefe;justify-self:center}body nav.small span.placeholder{width:1em;height:1em}body>*{min-width:0;min-height:0}body article{max-width:38rem;padding:0.5rem 2rem 0 2rem}body article>*{max-width:100%}body .next-chapter{width:100%}body .next-chapter a{display:flex;align-items:center;justify-content:flex-end;margin-right:0.5rem;font-size:1.2rem;text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#5babd1}body .next-chapter a:hover{color:#cf5ccd}body .next-chapter a span:first-child{margin-right:0.5rem}body footer{width:100%;text-align:right;display:flex;flex-direction:column;align-items:flex-end;justify-content:flex-end}@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:1rem 0.5rem 0 0.5rem;max-width:100%}}body.toc{display:flex;flex-direction:column;justify-content:flex-start;align-items:center}body.toc>*{width:36rem}body.toc header{margin-top:1rem;display:flex;flex-direction:column;align-items:center}body.toc header h1{font-size:3rem;font-weight:700;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0}body.toc header h2{font-size:1rem;font-weight:600;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0}body.toc header time{font-size:1rem;font-weight:400;font-family:"Crimson Pro","Georgia",Georgia,"Times New Roman",Times,serif}body.toc nav{background:none;display:flex;flex-direction:column;align-items:stretch}body.toc nav h1{text-align:left;font-size:2.5rem;font-weight:600;margin-bottom:0}body.toc nav ol li{font-size:1.5rem;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif}body.toc nav ol li a{text-decoration:none;margin:0 0 0.25rem 0;color:#5babd1}body.toc nav ol li a:hover{color:#cf5ccd}body.toc nav>ol{margin-left:0.5rem;margin-right:0.5rem}body.toc article,body.toc nav{padding:0}body.toc article>*,body.toc nav>*{margin-left:0.5rem;margin-right:0.5rem}body.toc footer{flex:1}@media screen and (max-width: 768px){body.toc>*{width:100%}body.toc header h1,body.toc header h2,body.toc header time{text-align:center}body.toc nav h1{font-size:1.75rem}}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}.icon-arrow-up{width:0.875em}.icon-list-ol{width:1em}@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%)}dl dt{border-right:1px solid #333333}footer{color:#cccccc}body nav.small{box-shadow:none}}@media print{body{background:#ffffff;color:#000000}body:not(.toc) nav{display:none}a{color:#000000;text-decoration:underline}h2,h3{break-after:avoid-page}figure{break-inside:avoid}p{orphans:2;widows:2}*{overflow:hidden}body{display:block}} +@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}img,svg,video{max-width:100%}figure{display:block;text-align:center;overflow-x:auto;margin:0 0 1em}figure figcaption{display:block;font-size:0.9rem;text-align:center}code,kbd{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.75rem}kbd{color:#222222;background:#eeeeee;box-shadow:0px 2px 4px rgba(0,0,0,0.5)}pre{overflow-x:auto;font-family:"Source Code Pro","Courier New",Courier,monospace;padding:0.5rem}dl{display:grid;grid-template-columns:auto auto}dl dt{font-weight:700;margin:0;padding:0 0.5rem 0.25rem;border-right:1px solid #dddddd;text-align:right}dl dd{margin:0;padding:0 0.5rem 0.25rem}dl dt p,dl dd p{margin:0}p{margin-top:0}footer{color:#444444}footer p{margin-right:0.5rem}table{margin:0 auto;border-collapse:collapse;border-spacing:0.5rem}table th{border-bottom:1px solid #eee}table th,table td{vertical-align:top}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;position:relative}body nav.big{background:#2c2c38;padding:0.5rem 1rem 1rem;max-width:15rem;position:sticky;display:flex;flex-direction:column}body nav.big header{margin:0 0 1rem;display:flex;flex-direction:column;align-items:stretch;border-bottom:2px solid #888888}body nav.big header h1{font-size:1.5rem;font-weight:700;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0;text-align:left;color:#eeeeee}body nav.big header h1 a{color:#eeeeee;text-decoration:none}body nav.big header h1 a:hover{color:#cf5ccd}body nav.big header h2{font-size:1rem;font-weight:600;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0;text-align:right;color:#eeeeee}body nav.big ol{margin:0 2rem;padding:0}body nav.big ol li{width:100%;font-size:1.25rem;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#eeeeee}body nav.big ol li a{text-decoration:none;margin:0 0 0.25rem 0;color:#5babd1}body nav.big ol li a:hover{color:#cf5ccd}body nav.big ol li a.current{color:#cf5ccd}body nav.big ol li a.current:hover{color:#fefefe}body nav.big ol li ol{margin:0 0 0 1rem}body nav.small{display:none;width:100%;align-items:center;justify-content:space-between;background:#2c2c38;padding:0;position:sticky;top:0;box-shadow:0px 2px 4px rgba(0,0,0,0.25)}body nav.small>*{margin:0.5rem}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{display:inline-flex;align-items:center}body nav.small span>*{margin-right:0.5rem}body nav.small span>*:last-child{margin-right:0}body nav.small span.title{text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#fefefe;justify-self:center}body nav.small span.placeholder{width:1em;height:1em}body>*{min-width:0;min-height:0}body article{max-width:38rem;padding:0.5rem 2rem 0 2rem}body article>*{max-width:100%}body article h1.title{font-size:2rem}body .next-chapter{width:100%}body .next-chapter a{display:flex;align-items:center;justify-content:flex-end;margin-right:0.5rem;font-size:1.2rem;text-decoration:none;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;color:#5babd1}body .next-chapter a:hover{color:#cf5ccd}body .next-chapter a span:first-child{margin-right:0.5rem}body footer{width:100%;text-align:right;display:flex;flex-direction:column;align-items:flex-end;justify-content:flex-end}@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:1rem 0.5rem 0 0.5rem;max-width:100%}body article h1.title{display:none}}body.toc{display:flex;flex-direction:column;justify-content:flex-start;align-items:center}body.toc>*{width:36rem}body.toc header{margin-top:1rem;display:flex;flex-direction:column;align-items:center}body.toc header h1{font-size:3rem;font-weight:700;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0}body.toc header h2{font-size:1rem;font-weight:600;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif;margin-bottom:0}body.toc header time{font-size:1rem;font-weight:400;font-family:"Crimson Pro","Georgia",Georgia,"Times New Roman",Times,serif}body.toc nav{background:none;display:flex;flex-direction:column;align-items:stretch}body.toc nav h1{text-align:left;font-size:2.5rem;font-weight:600;margin-bottom:0}body.toc nav ol li{font-size:1.5rem;font-family:"Poppins","Franklin Gothic Medium","Arial Narrow",Arial,sans-serif}body.toc nav ol li a{text-decoration:none;margin:0 0 0.25rem 0;color:#5babd1}body.toc nav ol li a:hover{color:#cf5ccd}body.toc nav>ol{margin-left:0.5rem;margin-right:0.5rem}body.toc article,body.toc nav{padding:0}body.toc article>*,body.toc nav>*{margin-left:0.5rem;margin-right:0.5rem}body.toc footer{flex:1}@media screen and (max-width: 768px){body.toc>*{width:100%}body.toc header h1,body.toc header h2,body.toc header time{text-align:center}body.toc nav h1{font-size:1.75rem}}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}.icon-arrow-up{width:0.875em}.icon-list-ol{width:1em}@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%)}dl dt{border-right:1px solid #333333}footer{color:#cccccc}body nav.small{box-shadow:none}}@media print{body{background:#ffffff;color:#000000}body:not(.toc) nav{display:none}a{color:#000000;text-decoration:underline}h2,h3{break-after:avoid-page}figure{break-inside:avoid}p{orphans:2;widows:2}*{overflow:hidden}body{display:block}} diff --git a/src/html.rs b/src/html.rs index ee95c2b..7cc6b43 100644 --- a/src/html.rs +++ b/src/html.rs @@ -231,7 +231,7 @@ fn generate_index(book: &FrontMatter, content: String, include_kat #[derive(Template)] #[template(path = "page.html")] -struct PageTemplate<'a, 'b, 'c, 'd, 'e, 'g> { +struct PageTemplate<'a, 'b, 'c, 'd, 'e, 'g, 'f> { chapter: &'a Chapter, content: &'b str, chapters: &'c Vec, @@ -240,9 +240,10 @@ struct PageTemplate<'a, 'b, 'c, 'd, 'e, 'g> { book: &'g FrontMatter, include_katex_css: bool, include_reload_script: bool, + root_offset: &'f str, } -fn format_page(book: &FrontMatter, chapter: &Chapter, chapters: &Vec, prev_chapter: Option<&Chapter>, next_chapter: Option<&Chapter>, content: &str, include_katex_css: bool, mut output: W, include_reload_script: bool) -> Result<(), Box> { +fn format_page(book: &FrontMatter, chapter: &Chapter, offset_root: bool, chapters: &Vec, prev_chapter: Option<&Chapter>, next_chapter: Option<&Chapter>, content: &str, include_katex_css: bool, mut output: W, include_reload_script: bool) -> Result<(), Box> { // fill out our template let template = PageTemplate { chapter, @@ -253,6 +254,7 @@ fn format_page(book: &FrontMatter, chapter: &Chapter, chapters: &V book, include_katex_css, include_reload_script, + root_offset: if offset_root { "../" } else { "" }, }; // and render! @@ -286,9 +288,17 @@ pub fn build, POut: AsRef>(src: PIn, dest: POut, include_ for (chapter_index, chapter) in book.chapters.iter().enumerate() { // render the index let chapter_root = dest.join(chapter.source.file_stem().map(std::ffi::OsStr::to_str).flatten().unwrap()); - let out = chapter_root.join("index.html"); - log::info!("Rendering `{}` into `{}`...", chapter.source.display(), out.display()); - fs::create_dir_all(&chapter_root)?; + let out = if chapter.sections.len() > 0 { + let out = chapter_root.join("index.html"); + log::info!("Rendering `{}` into `{}`...", chapter.source.display(), out.display()); + fs::create_dir_all(&chapter_root)?; + out + } + else { + let out = dest.join(format!("{}.html", chapter.source.file_stem().map(std::ffi::OsStr::to_str).flatten().unwrap())); + log::info!("Rendering `{}` into `{}`...", chapter.source.display(), out.display()); + out + }; let outfile = fs::File::create(&out)?; let outfile = io::BufWriter::new(outfile); @@ -306,7 +316,7 @@ pub fn build, POut: AsRef>(src: PIn, dest: POut, include_ None }; - format_page(&book.front, &chapter, &book.chapters, prev_chapter, next_chapter, &output, include_katex_css, outfile, include_reload_script)?; + format_page(&book.front, &chapter, chapter.sections.len() > 0, &book.chapters, prev_chapter, next_chapter, &output, include_katex_css, outfile, include_reload_script)?; prev_chapter = Some(chapter); // now the sections @@ -330,7 +340,7 @@ pub fn build, POut: AsRef>(src: PIn, dest: POut, include_ None }; - format_page(&book.front, §ion, &book.chapters, prev_chapter, next_chapter, &output, include_katex_css, outfile, include_reload_script)?; + format_page(&book.front, §ion, true, &book.chapters, prev_chapter, next_chapter, &output, include_katex_css, outfile, include_reload_script)?; prev_chapter = Some(section); } diff --git a/src/latex.rs b/src/latex.rs index 3bb2b7b..2d9564f 100644 --- a/src/latex.rs +++ b/src/latex.rs @@ -298,7 +298,25 @@ fn format_node<'a>(section_offset: u32, node: &'a comrak::nodes::AstNode<'a>, ou output.push_str("}}"); }, NodeValue::Image(node_link) => { - // TODO: download images? + let url = std::str::from_utf8(&node_link.url).expect("valid utf-8"); + if url.starts_with("http://") || url.starts_with("https://") { + // TODO: download images? + log::warn!("skipping image `{}` as we can't download images yet!", url); + } + else { + // TODO: make sure the file exists? + let title = std::str::from_utf8(&node_link.title).expect("valid utf-8"); + + output.push_str("\\begin{figure}[h]\n"); + output.push_str("\\centering\n"); + output.push_str("\\includegraphics[width=\\maxwidth{\\textwidth}]{"); + output.push_str(url); + output.push_str("}\n"); + output.push_str("\\caption{"); + output.push_str(title); + output.push_str("}\n"); + output.push_str("\\end{figure}\n"); + } }, NodeValue::FootnoteReference(label) => { let label = std::str::from_utf8(&label).expect("valid utf-8"); @@ -332,6 +350,7 @@ pub fn build, POut: AsRef>(src: PIn, dest: POut) -> Resul log::info!("created directory `{}`...", parent.display()); } } + let dest_path = dest.parent().unwrap_or(Path::new(".")).to_owned(); // load the book let mut book = super::load_book(&src)?; @@ -354,5 +373,29 @@ pub fn build, POut: AsRef>(src: PIn, dest: POut) -> Resul let rendered = latexbook.render()?; fs::write(dest, rendered)?; + // copy the assets + for entry in ignore::Walk::new(&src) { + let entry = entry?; + if let Some(t) = entry.file_type() { + if t.is_file() { + if let Some("md") = entry.path().extension().map(std::ffi::OsStr::to_str).flatten() { + // ignore markdown files + } + else { + // we found an asset to copy! + let dest_path: PathBuf = dest_path.join(entry.path().iter().skip(1).map(PathBuf::from).collect::()); + if let Some(parent) = dest_path.parent() { + if !parent.exists() { + fs::create_dir_all(parent)?; + log::info!("created directory `{}`...", parent.display()); + } + } + fs::copy(entry.path(), &dest_path)?; + log::info!("Copied `{}` to `{}`...", entry.path().display(), dest_path.display()); + } + } + } + } + Ok(()) } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a6a2781..9798e60 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,7 +129,7 @@ fn load_book>(src: P) -> Result> let contents = fs::read_to_string(&path)?; let (front, contents) = extract_frontmatter(&contents)?; - let front = front.unwrap_or_default().into_front(&book_front, name, &format!("{}/index.html", name)); + let front = front.unwrap_or_default().into_front(&book_front, name, &format!("{}.html", name)); chapters.push(Chapter { front, sections: Vec::new(), diff --git a/style/layout.scss b/style/layout.scss index 3574e4a..227712f 100644 --- a/style/layout.scss +++ b/style/layout.scss @@ -152,6 +152,10 @@ body { >* { max-width: 100%; } + + h1.title { + font-size: 2rem; + } } .next-chapter { @@ -204,6 +208,10 @@ body { article { padding: 1rem 0.5rem 0 0.5rem; max-width: 100%; + + h1.title { + display: none; + } } } } diff --git a/templates/book.tex b/templates/book.tex index 5bae6ac..e0d8285 100644 --- a/templates/book.tex +++ b/templates/book.tex @@ -41,6 +41,15 @@ % better lists \usepackage{enumitem} +% better copyright symbol +\usepackage{textcomp} + +% images +\usepackage{graphicx} +\makeatletter +\def\maxwidth#1{\ifdim\Gin@nat@width>#1 #1\else\Gin@nat@width\fi} +\makeatother + \title{ {{ front.title }} } \author{ {{ front.author }} } \date{ {{ front.pubdate|human_date }} } @@ -56,7 +65,7 @@ \topskip0pt \vspace*{\fill} \begin{center} -\textcopyright{} {{ front.pubdate|year }} {{ front.author }} +\textcopyright {{ front.pubdate|year }} {{ front.author }} \end{center} \vspace*{\fill} diff --git a/templates/page.html b/templates/page.html index bd9597c..a78f48a 100644 --- a/templates/page.html +++ b/templates/page.html @@ -4,8 +4,8 @@ {{ book.title }} | {{ chapter.front.title }} - - + + @@ -18,17 +18,17 @@