Skip to content

Commit

Permalink
Add a minimal theme a new project can be started with
Browse files Browse the repository at this point in the history
  • Loading branch information
grego committed Jul 15, 2024
1 parent 4b169b6 commit 42f0e71
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blades"
version = "0.5.0"
version = "1.0.0"
authors = ["Maroš Grego <maros@grego.site>"]
edition = "2021"
description = "Blazing fast dead simple static site generator"
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="https://raw.githubusercontent.com/grego/blades/master/logo.svg?sanitize=true" alt="Blades logo" width="250" align="right">
<img src="https://raw.githubusercontent.com/grego/blades/master/examples/assets/logo.svg?sanitize=true" alt="Blades logo" width="250" align="right">

# Blades

Expand Down Expand Up @@ -30,8 +30,10 @@ to let you focus on your content.
* Themes
* Image gallery generation
* [CommonMark](https://commonmark.org) markdown with tables and footnotes for content
* Automatic syntax highlighting using [cmark-syntax](https://github.com/grego/cmark-syntax)
(with a possibility of turning LaTeX formulas into [MathML](https://developer.mozilla.org/docs/Web/MathML))
* Rendering of LaTeX formulas into [MathML](https://developer.mozilla.org/docs/Web/MathML),
(supported by [all major browsers](https://caniuse.com/mathml)), with content between
`$` rendered in inline mode and content between `$$` rendered in display mode.
* Syntax highlighting using [cmark-syntax](https://github.com/grego/cmark-syntax)
* Customizable taxonomies (like categories or tags)
* Pagination
* Breadcrumbs
Expand Down Expand Up @@ -93,19 +95,15 @@ There are 4 types of plugins that can be used with Blades.
* **transform** - they receive a JSON-serialised list of [pages](https://www.getblades.org/pages.html) on the standard output and output
another such list on the standard output, can transform anything on the pages
* **content** - they receive a markdown content of one page on standard input and output markdown on the standard output; they are enabled
on per-page basis and can be used e.g. to render LaTeX formulas or highlight syntax
on per-page basis

Any code in any language can be used, as only using the standard input and output is assumed. For Rust, Blades also provides a
[library](https://docs.rs/blades) for automatic serialisation and deserialisation pages.

### Example
Example plugin configuration can be found in [examples](examples/Blades.toml), as well as an
example toy [transform plugin](examples/transform_plugin.rs).
To try it, first downolad the [Casper](https://blades-casper.netlify.app/) theme as a submodule
```bash
git submodule update --init
```
Then build the plugin:
To try it, first build the plugin:
```bash
cargo build --release transform_plugin
```
Expand All @@ -126,6 +124,9 @@ into the `themes` directory. A list of available themes can be found [here](http
To overwrite the theme, simply use the files in the `templates`, resp. `assets` subdirectories of the
page root directory.

When initializing a Blades project with `blades init`, it provides an option to start with
a minimal working template to allow you to quickly start working on your content.

## Assets
All the files from the `assets` directory (and from the theme) are moved into the directory
specified in the [config](https://www.getblades.org/config.html), which is emptied before. This is a subdirectory of the
Expand Down
3 changes: 0 additions & 3 deletions examples/Blades.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
title = "My site!"
description = "It does nothing"
image = "img/main.jpg"
theme = "casper"

[plugins]
input = ["cat input.json"]
Expand Down
File renamed without changes
20 changes: 1 addition & 19 deletions examples/content/gallery.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,10 @@ With this generator
gallery = true

[[pictures]]
file = "1"
file = "/assets/logo.svg"
alt = "A trash can."
caption = "a view of reality"
pid = "tiles"

[[pictures]]
file = "2"
alt = "A manor"
caption = "a view from reality"
pid = "manor"

[[pictures]]
file = "3"
alt = "A brick factory"
caption = "a view above reality"
pid = "factory"

[[pictures]]
file = "4"
alt = "A couch outside"
caption = "a view with reality"
pid = "real"

[taxonomies]
tags = ["finger", "lisp"]
14 changes: 8 additions & 6 deletions examples/content/mu.toml → examples/content/mu.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
+++
title = "Mu"
date = 2020-09-18
image = "img/mu.jpg"
summary = """A monk asked Joshu, "Has the dog the Buddha nature?" """
content = """
A monk asked Joshu, "Has the dog the Buddha nature?"[^cool]

[taxonomies]
tags = ["pets"]
+++
A monk asked Joshu, "Has the dog the Buddha nature?"[^cool]
Joshu replied, "Mu"

$$\sum_{n=0}^\infty \frac{1}{n^2}$$

### Mumon's Comment:
> For the pursuit of Zen, you must pass through the barriers (gates) set up by the Zen masters. To attain his mysterious awareness one must completely uproot all the normal workings of one's mind. If you do not pass through the barriers, nor uproot the normal workings of your mind, whatever you do and whatever you think is a tangle of ghost. Now what are the barriers? This one word "Mu" is the sole barrier. This is why it is called the Gateless Gate of Zen. The one who passes through this barrier shall meet with Joshu face to face and also see with the same eyes, hear with the same ears and walk together in the long train of the patriarchs. Wouldn't that be pleasant?
> Would you like to pass through this barrier? Then concentrate your whole body, with its 360 bones and joints, and 84,000 hair follicles, into this question of what "Mu" is; day and night, without ceasing, hold it before you. It is neither nothingness, nor its relative "not" of "is" and "is not." It must be like gulping a hot iron ball that you can neither swallow nor spit out.
Expand All @@ -20,7 +26,3 @@ pub(crate) fn render_content<E: Encoder>(source: &str, encoder: &mut E) -> Resul
```

[^cool]: This is a really cool story.
"""

[taxonomies]
tags = ["pets"]
16 changes: 16 additions & 0 deletions examples/templates/gallery.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="{{site lang}}" style="max-width: 70ch; padding: 3em 1em; margin: auto; font: 1.25em/1.5 sans-serif">
<head>
<title>{{#parent title}}{{title}} | {{/title parent}}{{site title}}</title>
<meta charset="utf-8"/>
</head>
<body>
{{#current}}<figure>
<img alt="{{alt}}" src="{{file}}" />
<figcaption>{{caption}}</figcaption>
</figure>{{/current}}
{{#previous}}<a href="{{permalink}}">&larr;</a>{{/previous}}
{{#parent}}<a href="{{permalink}}">{{title}}</a>{{/parent}}
{{#next}}<a href="{{permalink}}">&rarr;</a>{{/next}}
</body>
</html>
18 changes: 18 additions & 0 deletions examples/templates/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="{{site lang}}" style="max-width: 70ch; padding: 3em 1em; margin: auto; font: 1.25em/1.5 sans-serif">
<head>
<title>{{#title}}{{title}} | {{/title}}{{site title}}</title>
<meta charset="utf-8"/>
</head>
<body>
<h1>{{title}}</h1>
<p>{{#date}}{{d}}/{{m}}/{{y}} | {{/date}}<a href="{{index permalink}}">{{site title}}</a></p>
{{content}}
{{#pictures}}<a href="{{permalink}}">
<figure class="small-figure">
<img alt="{{alt}}" src="{{file}}"/>
<figcaption class="gallery-caption">{{caption}}</figcaption>
</figure>
</a>{{/pictures}}
</body>
</html>
20 changes: 20 additions & 0 deletions examples/templates/section.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="{{site lang}}" style="max-width: 70ch; padding: 3em 1em; margin: auto; font: 1.25em/1.5 sans-serif">
<head>
<title>{{#title}}{{title}} | {{/title}}{{site title}}</title>
<meta charset="utf-8"/>
</head>
<body>
<h1>{{title}}</h1>
<nav>{{#subsections}}<p><a href="{{permalink}}">{{title}}</a></p>{{/subsections}}</nav>
{{content}}
<nav>{{#pages}}<p>{{#date}}<div>{{d}}/{{m}}/{{y}}</div>{{/date}}
<a href="{{permalink}}">{{title}}</a></p>{{/pages}}</nav>
{{#pictures}}<a href="{{permalink}}">
<figure class="small-figure">
<img alt="{{alt}}" src="{{file}}"/>
<figcaption class="gallery-caption">{{caption}}</figcaption>
</figure>
</a>{{/pictures}}
</body>
</html>
12 changes: 12 additions & 0 deletions examples/templates/taxonomy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="{{site lang}}" style="max-width: 70ch; padding: 3em 1em; margin: auto; font: 1.25em/1.5 sans-serif">
<head>
<title>{{#title}}{{title}} | {{/title}}{{site title}}</title>
<meta charset="utf-8"/>
</head>
<body>
<h1>{{title}}</h1>
{{description}}
<nav>{{#keys}}<p><a href="{{key}}">{{key}}</a></p>{{/keys}}</nav>
</body>
</html>
13 changes: 13 additions & 0 deletions examples/templates/taxonomy_key.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="{{site lang}}" style="max-width: 70ch; padding: 3em 1em; margin: auto; font: 1.25em/1.5 sans-serif">
<head>
<title>{{#title}}{{title}} | {{/title}}{{site title}}</title>
<meta charset="utf-8"/>
</head>
<body>
<h1>{{taxonomy title}}: {{title}}</h1>
{{#site}}<a href="{{url}}">{{title}}</a>{{/site}}
<nav>{{#pages}}<p>{{#date}}<div>{{d}}/{{m}}/{{y}}</div>{{/date}}
<a href="{{permalink}}">{{title}}</a></p>{{/pages}}</nav>
</body>
</html>
1 change: 0 additions & 1 deletion examples/themes/casper
Submodule casper deleted from 54c947
62 changes: 57 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,33 @@ fn init() -> Result<(), Error> {
let config = MockConfig { title, author };
Template::new(include_str!("templates/Blades.toml"))?.render_to_file(CONFIG_FILE, &config)?;
fs::create_dir_all("content")?;
fs::create_dir_all("themes").map_err(Into::into)
let thm = next_line(&mut lines, "Start with a minimal working template? (Select no to use a theme; then put the theme inside the 'themes' directory.) [Y/n]")?;
if &thm == "n" || &thm == "N" || &thm == "no" || &thm == "No" {
fs::create_dir_all("themes").map_err(Into::into)
} else {
fs::create_dir_all("templates")?;
fs::write(
"templates/page.html",
include_str!("../examples/templates/page.html"),
)?;
fs::write(
"templates/section.html",
include_str!("../examples/templates/section.html"),
)?;
fs::write(
"templates/taxonomy.html",
include_str!("../examples/templates/taxonomy.html"),
)?;
fs::write(
"templates/taxonomy_key.html",
include_str!("../examples/templates/taxonomy_key.html"),
)?;
fs::write(
"templates/gallery.html",
include_str!("../examples/templates/gallery.html"),
)?;
Ok(())
}
}

/// Create a new page and edit it if the EDITOR variable is set
Expand Down Expand Up @@ -456,6 +482,24 @@ fn cleanup(mut rendered: Vec<PathBuf>, filelist: &str) -> Result<(), io::Error>
Ok(())
}

/// A helper trait to print the name of the file that was not found.
trait PrintIfNotFound {
/// Print the name of the file that was not found.
fn print_if_not_found(self, name: &str) -> Self;
}

impl<T> PrintIfNotFound for io::Result<T> {
/// Print the name of the file that was not found.
fn print_if_not_found(self, name: &str) -> Self {
if let Err(ref e) = self {
if e.kind() == ErrorKind::NotFound {
eprintln!("Error: {} not found", name)
}
}
self
}
}

/// The actual logic of task parallelisation.
fn build(config: &Config) -> Result<(), Error> {
const MIN_PER_THREAD: usize = 5;
Expand Down Expand Up @@ -492,7 +536,12 @@ fn build(config: &Config) -> Result<(), Error> {
.plugins
.input
.iter()
.map(|cmd| cmd.make_command().output()?.output_result(&cmd.path))
.map(|cmd| {
cmd.make_command()
.output()
.print_if_not_found(&cmd.path)?
.output_result(&cmd.path)
})
.collect::<Result<Vec<_>, _>>()?;
let input_pages = inputs
.iter()
Expand All @@ -509,7 +558,8 @@ fn build(config: &Config) -> Result<(), Error> {
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?;
.spawn()
.print_if_not_found(&cmd.path)?;
let mut stdin = child.stdin.take().expect("Failed to open child stdin");
if let Some(ref source) = transformed {
stdin.write_all(source)?;
Expand All @@ -535,7 +585,8 @@ fn build(config: &Config) -> Result<(), Error> {
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?;
.spawn()
.print_if_not_found(&config.plugins.content[cmd].path)?;
let mut stdin = child.stdin.take().expect("Failed to open child stdin");
if let Some(ref out) = output {
stdin.write_all(out.as_ref())?;
Expand Down Expand Up @@ -618,7 +669,8 @@ fn build(config: &Config) -> Result<(), Error> {
.make_command()
.stdin(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?;
.spawn()
.print_if_not_found(&cmd.path)?;
let mut stdin = child.stdin.take().expect("Failed to open child stdin");
stdin.write_all(pagedata.as_ref())?;
drop(stdin);
Expand Down

0 comments on commit 42f0e71

Please sign in to comment.