#github #html #web-page #html-parser #framework #javascript #static

antwerp

从 JavaScript 移植到 Rust 的开源框架,用于 GitHub 页面,并使用 Marcus HTML 到 MarkDown 解析器构建

2 个版本

0.3.3 2023年2月22日
0.3.2 2022年11月19日
0.2.4 2022年8月21日
0.1.4 2022年7月31日

#26#web-page

Download history 7/week @ 2024-03-31 91/week @ 2024-07-07

91 每月下载量

MIT 许可证

23KB
162

Antwerp

Antwerp 是一个从 JavaScript 移植到 Rust 的开源框架,用于 GitHub 页面,并使用 Marcus HTML 到 MarkDown 解析器构建。它使用 public/ 中的 HTML 和 MarkDown 模板输出静态网页到 dist/,这些模板使用 Marcus MarkDown 到 HTML 解析器转换为 HTML。

演示

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();
}

输入

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 %}

输出

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>

参考

Antwerp:

Marcus:

MarkDown/HTML:

许可证

此仓库包含的源代码免费分发,受 MIT 许可证 保护,完整许可证请见 LICENSE.md

依赖关系

~3.5–5MB
~109K SLoC