#markdown-html #github #web-page #markdown-parser #web-framework #template #static

antwerp

An open-source framework ported from JavaScript to Rust for GitHub pages and built with the Marcus HTML to MarkDown parser

2 releases

0.3.3 Feb 22, 2023
0.3.2 Nov 19, 2022
0.2.4 Aug 21, 2022
0.1.4 Jul 31, 2022

#2220 in Web programming

MIT license

23KB
162 lines

Antwerp

Antwerp is an open-source framework ported from JavaScript to Rust for GitHub pages and built with the Marcus HTML to MarkDown parser. It outputs static web pages in dist/ using HTML and MarkDown templates in public/, which are converted to HTML using the Marcus MarkDown to HTML parser.

Demonstration:

Cargo.toml (Cargo.toml):

[package]
name = "<NAME>"
version = "<VERSION>"
edition = "2021"
description = "<DESCRIPTION>"
license = "MIT"
readme = "README.md"

[dependencies]
antwerp = "0.3.1"

main.rs (src/main.rs):

use antwerp;

fn main() {
  antwerp::build();
}

Input:

base.html (public/base.html):

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>{% block title | text | trim %}{% endblock title %}</title>
</head>
<body>
  {% block body %}
    <p>This paragraph serves as the default content for the <code>body</code> block.</p>
  {% endblock body %}

  <footer>
    {% block footer | trim | text %}
      # This is a header for the default footer (it won't get converted to HTML).
    {% endblock footer %}
  </footer>
</body>
</html>

index.md (public/index.md):

{% extends "base.html" %}

{% block title %}Homepage{% endblock title %}

{% block body %}
# Hello World!

This is the template, it contains a link to [a file](/section/chapter/file.html) in the first chapter of a random section and the default footer (below).
{% endblock body %}

file.md (public/section/chapter/file.md):

{% extends "base.html" %}
{% block title %}Section / Chapter / File{% endblock title %}

{% block body %}
# Hello World!

This is the template, it takes you to [the homepage](/).

This page also includes CSS styles, which are ignored by the [Marcus](https://crates.io/crates/marcus) MarkDown to HTML converter.

<style type="text/css">
  a {
    color: hotpink !important;
    text-decoration: none
  }
  h1 {
    font-family: sans-serif
  }
</style>
{% endblock body %}

{% block footer %}
  <footer>
    This is a custom footer for the `section / chapter / file` page.
  </footer>
{% endblock footer %}

Output:

index.html (dist/index.html):

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title><p>Homepage</p></title>
</head>
<body>
  <h1>Hello World!</h1>

<p>This is the template, it contains a link to <a href="/section/chapter/file.html">a file</a> in the first chapter of a random section and the default footer (below).</p>

  <footer>
    # This is a header for the default footer (it won't get converted to HTML).
  </footer>
</body>
</html>

file.md (dist/section/chapter/file.md):

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title><p>Section / Chapter / File</p></title>
</head>
<body>
  <h1>Hello World!</h1>

<p>This is the template, it takes you to <a href="/">the homepage</a>.</p>

<p>This page also includes CSS styles, which are ignored by the <a href="https://crates.io/crates/marcus">Marcus</a> MarkDown to HTML converter.</p>

<style type="text/css">
  a {
    color: hotpink !important;
    text-decoration: none
  }
  h1 {
    font-family: sans-serif
  }
</style>

  <footer>
    <footer>

<p> This is a custom footer for the <code>section / chapter / file</code> page.</p>
  </footer>
  </footer>
</body>
</html>

References:

Antwerp:

Marcus:

MarkDown/HTML:

Licence:

The source code included in this repository is distributed, for free, under the MIT Licence, for the full license, see LICENSE.md.

Dependencies

~4.5–6.5MB
~118K SLoC