[v0.1.0] - Update README.md

pull/3/head
sgoudham 3 years ago
parent 75e7609610
commit 0783ed7aa0
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -43,10 +43,10 @@ Given the following directory structure
```text ```text
book.toml book.toml
src src
├── one.md ├── rust.md
├── two.md ├── go.md
├── two ├── friends
│ └── three.md │ └── hazel.md
├── images ├── images
│ ├── ferris.png │ ├── ferris.png
│ └── corro.png │ └── corro.png
@ -56,11 +56,13 @@ src
If we wanted to include the images `ferris.png` and `corro.png` within all the files through a footer, we'd have to copy If we wanted to include the images `ferris.png` and `corro.png` within all the files through a footer, we'd have to copy
the same piece of markdown/code in every file and set a unique path back to the `images/` directory. the same piece of markdown/code in every file and set a unique path back to the `images/` directory.
This is where `mdbook-template` can help. This is where `mdbook-template` can help with the introduction of `{{#template ...}`.
Being based on the `{{#include ... }}` feature of mdbook, mdbook-template allows you to use familiar syntax to include Being based on the `{{#include ... }}` feature of mdbook, mdbook-template allows you to use familiar syntax to include
files while passing in arguments to allow for dynamic generation of text. files while passing in arguments to allow for dynamic generation of text.
Please view the given [example](#example) which demonstrates it in action.
## Format ## Format
The format is as follows The format is as follows
@ -77,6 +79,48 @@ The format is as follows
Arguments to be replaced within the template files should be wrapped in `{}` Arguments to be replaced within the template files should be wrapped in `{}`
## Valid Configurations
```markdown
# Valid
{{#template file.txt path=../images author=Goudham}}
# Valid
{{#template
file.txt
path=../images
author=Goudham
}}
# Valid
// Not recommended but valid
{{#template file.txt path=../images author=Goudham}}
# Valid
// Not recommended but valid
{{#template
file.txt
path=../images
author=Goudham
}}
# Invalid
// Use {{#include}} for simply including files
{{#template file.txt}}
# Invalid
{{#template
file.txt
path=../images
author=Goudham}}
# Invalid
{{#template file.txt
path=../images
author=Goudham
}}
```
## Example ## Example
Given the following directory Given the following directory
@ -84,10 +128,10 @@ Given the following directory
```text ```text
book.toml book.toml
src src
├── one.md ├── rust.md
├── two.md ├── go.md
├── two ├── friends
│ └── three.md │ └── hazel.md
├── images ├── images
│ ├── ferris.png │ ├── ferris.png
│ └── corro.png │ └── corro.png
@ -101,77 +145,77 @@ and the following content
`templates/footer.md` `templates/footer.md`
```markdown ```markdown
- - - - -- Designed By {authors} --
Designed By Goudham
![ferris]({path}/ferris.png) ![ferris]({path}/ferris.png)
![ferris]({path}/corro.png) ![corro]({path}/corro.png)
``` ```
`one.md` `rust.md`
```markdown ```markdown
# One # Rust
Some Content... Some Content...
{{#template templates/footer.md path=images}} {{#template templates/footer.md authors=Goudham, Hazel path=images}}
``` ```
`two.md` `go.md`
```markdown ```markdown
# Two # Go
Some Content... Some Content...
{{#template templates/footer.md path=images}} {{#template templates/footer.md path=images authors=Goudham, Hazel}}
``` ```
`two/three.md` `friends/hazel.md`
```markdown ```markdown
# Three # Hazel
Some Content... Some Content...
{{#template templates/footer.md path=../images}} {{#template
templates/footer.md
path=../images
authors=Goudham, Hazel
}}
``` ```
After running `mdbook build` with the mdbook-template preprocessor enabled, the files will have dynamic paths to the After running `mdbook build` with the mdbook-template preprocessor enabled, the files will have dynamic paths to the
images images and contain **_identical_** content.
`one.md` `rust.md`
```markdown ```markdown
# One # Rust
Some Content... Some Content...
- - - - -- Designed By Goudham, Hazel --
Designed By Goudham
![ferris](images/ferris.png) ![ferris](images/ferris.png)
![ferris](images/corro.png) ![corro](images/corro.png)
``` ```
`two.md` `go.md`
```markdown ```markdown
# Two # Go
Some Content... Some Content...
- - - - -- Designed By Goudham, Hazel --
Designed By Goudham
![ferris](images/ferris.png) ![ferris](images/ferris.png)
![ferris](images/corro.png) ![corro](images/corro.png)
``` ```
`two/three.md` `friends/hazel.md`
```markdown ```markdown
# Three # Hazel
Some Content... Some Content...
- - - - -- Designed By Goudham, Hazel --
Designed By Goudham
![ferris](../images/ferris.png) ![ferris](../images/ferris.png)
![ferris](../images/corro.png) ![corro](../images/corro.png)
``` ```
Further examples are included within the [](/examples) section which demonstrate a variety of usages. Further examples are included within the [examples](/examples) directory which demonstrate a variety of usages.
## License ## License
[MIT](LICENSE) [MIT License](LICENSE)
## Contributing ## Contributing

Loading…
Cancel
Save