-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
306 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Djot command reference | ||
|
||
[Back to main page](./index.md) | ||
|
||
## Installation | ||
|
||
```shell | ||
cargo install simple-ssg | ||
``` | ||
|
||
## Building Locally | ||
|
||
```shell | ||
git clone https://github.com/ryanabx/simple-ssg | ||
cd simple-ssg | ||
cargo build --release | ||
``` | ||
|
||
## Usage | ||
|
||
```shell | ||
Plain and simple static site generator for Djot and Markdown light markup languages | ||
|
||
Usage: simple-ssg [OPTIONS] [DIRECTORY] | ||
|
||
Arguments: | ||
[DIRECTORY] Path to the directory to use to generate the site (not required if -f is specified) | ||
|
||
Options: | ||
-f <FILE> Process a single file instead of a directory | ||
-o <OUTPUT_PATH> Optional output path override. Defaults to ./output for directories | ||
--clean Clean the output directory before generating the site. Useful for multiple runs | ||
--web-prefix <WEB_PREFIX> Specify the website prefix (defaults to local paths i.e. `./`) | ||
-t, --template <TEMPLATE> Specify a built in template to use (will override a template.html in any directory!). defaults to whatever templates are found in template.html in the directories [possible values: github-markdown, force-none] | ||
-h, --help Print help | ||
-V, --version Print version | ||
``` | ||
## Debugging | ||
> *TIP:* Use the `RUST_LOG` environment variable to change the log level of the application: \ | ||
> i.e. `RUST_LOG=trace simple-ssg ...` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[Back to home page](../index.md) | ||
|
||
# Contact Ryanabx | ||
|
||
- [Mastodon](https://mastodon.social/@ryanabx) | ||
- [GitHub](https://github.com/ryanabx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Djot example | ||
|
||
--- | ||
|
||
This is a simple djot example to showcase this static site generator! It gets put into the template called `template.html` in the home directory of this documentation, and as a result it has some nice formatting and a simple table of contents! The template is of course not required though :) | ||
|
||
--- | ||
|
||
For more, see the [Markdown example](./markdown-example.md) and go to the command reference at [../command_reference.md](../command_reference.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# SMPL Static Site Generator | ||
|
||
<https://github.com/ryanabx/simple-ssg> | ||
|
||
[Command Reference](./command_reference) | ||
|
||
## A simple static site generator for Djot/Markdown! | ||
|
||
### What is Djot? | ||
|
||
[Djot](https://github.com/jgm/djot) is a light markup language created by [John MacFarlane](https://github.com/jgm), who was consequential in developing [CommonMark](https://commonmark.org/), which is a standardized variant of Markdown. | ||
|
||
### Why Djot and not Markdown? | ||
|
||
I decided to make this simple generator because the tooling for Djot is actually quite nice. The reference parser is written in TypeScript, but there is a parser written in rust which I'm using for this project called [Jotdown](https://github.com/hellux/jotdown). One of Djot's goals is to have single-pass parsing, and the rules are much simpler than Markdown, leaving less up to interpretation. This makes writing a parser for Djot very simple compared to having to interpret edge cases in Markdown. | ||
|
||
The syntax of Djot is very similar to Markdown, but it removes some of the inconsistencies that couldn't be removed in CommonMark. John MacFarlane has a great blog post with some of the ideas that made it into Djot, see <https://johnmacfarlane.net/beyond-markdown.html>. | ||
|
||
### Why make a static site generator? | ||
|
||
Honestly, I was just wanting a bit more tooling for Djot. I created a [Visual studio code plugin](https://github.com/ryanabx/djot-vscode), and decided I wanted to have more fun with Djot. Since I build projects in rust, I'm thankful that Jotdown exists to take care of the parsing part for me, all I had to do was handle the conversions. | ||
|
||
The scope of this generator is pretty simple, no table of contents, no sidebar, just raw Djot parsing. There are some nice warnings that the generator will let you know about though! | ||
|
||
- A warning if `index.dj || index.djot` doesn't exist. Most sites will use `index.html` as the entry point to a site | ||
- A warning if a local link is broken | ||
- A warning if a path in the directory walk is not relative to the target directory (this should pretty much never happen, but it's there just in case) | ||
|
||
You can also use the `--no-warn` argument to turn warnings into errors, if you value having an absolutely "correct" website generated! | ||
|
||
See more from me at <https://github.com/ryanabx> | ||
|
||
![ryanabx profile photo](https://avatars.githubusercontent.com/u/56272643?v=4) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<p><a href="./">..</a> | ||
<a href="./contact-ryanabx.dj">contact-ryanabx.dj</a></p> | ||
<p><a href="./djot-example.dj">djot-example.dj</a></p> | ||
<p><a href="./markdown-example.html">markdown-example.md</a></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<h1>Markdown example</h1> | ||
<p>This static site generator also supports Markdown, using <a href="https://github.com/pulldown-cmark/pulldown-cmark">pulldown-cmark</a>!</p> | ||
<p>This provides an example of using markdown alongside djot documents in the same static site! See: <a href="../index.dj">../index.dj</a> for the home page, and <a href="../command_reference.dj">../command_reference</a> for the command reference!</p> | ||
<p>Contact me <a href="contact-ryanabx.dj">here</a></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<h1>Templating</h1> | ||
<p>Using templates in <code>simple-ssg</code> is simple! All you need to do is provide a <code>template.html</code> file in any directory of your documentation.</p> | ||
<blockquote> | ||
<p><strong>NOTE:</strong> A nested <code>template.html</code> will take priority over a parent folder's <code>template.html</code></p> | ||
</blockquote> | ||
<p>An example template could be this:</p> | ||
<pre><code class="language-html"><!DOCTYPE html> | ||
<html> | ||
<head> | ||
<style> | ||
<!-- insert a style here --> | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Contents:</h1> | ||
<!-- {TABLE_OF_CONTENTS} --> | ||
<hr> | ||
<!-- {CONTENT} --> | ||
</body> | ||
</html> | ||
</code></pre> | ||
<p>This template contains two macros, the <code><!-- {TABLE_OF_CONTENTS} --></code> macro which provides a simple bulleted list of all the page links for your static site, and <code><!-- {CONTENT} --></code>, which is where the output of the Markdown and Djot converters goes.</p> | ||
<h2>Built-in Templates</h2> | ||
<p>There is currently one built-in template: <code>github-markdown</code>. Use the <code>-t</code> option to specify this template. You may also use <code>-t force-none</code> to force a blank page without a template!</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use std::path::Path; | ||
|
||
use pulldown_cmark::{CowStr, Options}; | ||
|
||
|
||
/// Take markdown input, and change links if necessary | ||
pub fn md_to_html( | ||
markdown: &str, | ||
file_parent_dir: &Path, | ||
web_prefix: Option<&str>, | ||
) -> anyhow::Result<String> { | ||
log::info!("Markdown to html: {:?}", file_parent_dir); | ||
let mut options = Options::empty(); | ||
options.insert(Options::ENABLE_GFM); | ||
let events = pulldown_cmark::Parser::new_ext(markdown, options) | ||
.map(|event| -> anyhow::Result<pulldown_cmark::Event> { | ||
match event { | ||
pulldown_cmark::Event::Start(pulldown_cmark::Tag::Link { | ||
link_type, | ||
dest_url, | ||
title, | ||
id, | ||
}) => { | ||
let inner = dest_url.to_string(); | ||
let referenced_path = file_parent_dir.join(&inner); | ||
if referenced_path | ||
.extension() | ||
.is_some_and(|ext| ext == "md") | ||
{ | ||
let new_path = Path::new(&inner).with_extension("html"); | ||
log::info!("Path: {:?} -> {:?}", &inner, &new_path); | ||
if !referenced_path.exists() { | ||
log::warn!("Path {:?} doesn't exist!", referenced_path); | ||
Ok(pulldown_cmark::Event::Start(pulldown_cmark::Tag::Link { | ||
link_type, | ||
dest_url, | ||
title, | ||
id, | ||
})) | ||
} | ||
else { | ||
// Create destination url | ||
let dest_url = CowStr::Boxed( | ||
format!("{}{}", web_prefix.unwrap_or(""), new_path.to_string_lossy()) | ||
.into_boxed_str(), | ||
); | ||
Ok(pulldown_cmark::Event::Start(pulldown_cmark::Tag::Link { | ||
link_type, | ||
dest_url, | ||
title, | ||
id, | ||
})) | ||
} | ||
} else { | ||
Ok(pulldown_cmark::Event::Start(pulldown_cmark::Tag::Link { | ||
link_type, | ||
dest_url, | ||
title, | ||
id, | ||
})) | ||
} | ||
} | ||
_ => Ok(event), | ||
} | ||
}) | ||
.collect::<Result<Vec<pulldown_cmark::Event>, _>>()?; | ||
log::info!("Done"); | ||
let mut html = String::new(); | ||
pulldown_cmark::html::push_html(&mut html, events.iter().cloned()); | ||
Ok(html) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters