swap to tera in place of handlebars

This commit is contained in:
zyl 2024-11-04 17:09:11 -08:00
parent 76c75a40d9
commit ee48eae327
Signed by: zyl
SSH key fingerprint: SHA256:uxxbSXbdroP/OnKBGnEDk5q7EKB2razvstC/KmzdXXs
25 changed files with 407 additions and 184 deletions

284
Cargo.lock generated
View file

@ -44,6 +44,21 @@ version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.6.18"
@ -160,6 +175,16 @@ dependencies = [
"generic-array",
]
[[package]]
name = "bstr"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40723b8fb387abc38f4f4a37c09073622e41dd12327033091ef8950659e6dc0c"
dependencies = [
"memchr",
"serde",
]
[[package]]
name = "bumpalo"
version = "3.16.0"
@ -199,7 +224,32 @@ version = "0.4.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
dependencies = [
"android-tzdata",
"iana-time-zone",
"num-traits",
"windows-targets 0.52.6",
]
[[package]]
name = "chrono-tz"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93698b29de5e97ad0ae26447b344c482a7284c737d9ddc5f9e52b74a336671bb"
dependencies = [
"chrono",
"chrono-tz-build",
"phf 0.11.2",
]
[[package]]
name = "chrono-tz-build"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c088aee841df9c3041febbb73934cfc39708749bf96dc827e3359cd39ef11b1"
dependencies = [
"parse-zoneinfo",
"phf 0.11.2",
"phf_codegen 0.11.2",
]
[[package]]
@ -274,6 +324,12 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "cpufeatures"
version = "0.2.14"
@ -449,6 +505,12 @@ dependencies = [
"syn 2.0.87",
]
[[package]]
name = "deunicode"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "339544cc9e2c4dc3fc7149fd630c5f22263a4fdf18a98afd0075784968b5cf00"
[[package]]
name = "digest"
version = "0.10.7"
@ -720,6 +782,30 @@ version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "globset"
version = "0.4.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15f1ce686646e7f1e19bf7d5533fe443a45dbfb990e00629110797578b42fb19"
dependencies = [
"aho-corasick",
"bstr",
"log",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "globwalk"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757"
dependencies = [
"bitflags 2.6.0",
"ignore",
"walkdir",
]
[[package]]
name = "grass"
version = "0.13.4"
@ -762,21 +848,6 @@ dependencies = [
"tracing",
]
[[package]]
name = "handlebars"
version = "6.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd4ccde012831f9a071a637b0d4e31df31c0f6c525784b35ae76a9ac6bc1e315"
dependencies = [
"log",
"num-order",
"pest",
"pest_derive",
"serde",
"serde_json",
"thiserror",
]
[[package]]
name = "hashbrown"
version = "0.13.2"
@ -888,6 +959,15 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
name = "humansize"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7"
dependencies = [
"libm",
]
[[package]]
name = "hyper"
version = "0.14.31"
@ -912,6 +992,29 @@ dependencies = [
"want",
]
[[package]]
name = "iana-time-zone"
version = "0.1.61"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]]
name = "icu_collections"
version = "1.5.0"
@ -1057,6 +1160,22 @@ dependencies = [
"icu_properties",
]
[[package]]
name = "ignore"
version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d89fd380afde86567dfba715db065673989d6253f42b88179abd3eae47bda4b"
dependencies = [
"crossbeam-deque",
"globset",
"log",
"memchr",
"regex-automata",
"same-file",
"walkdir",
"winapi-util",
]
[[package]]
name = "indenter"
version = "0.3.3"
@ -1176,6 +1295,12 @@ version = "0.2.161"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"
[[package]]
name = "libm"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa"
[[package]]
name = "libredox"
version = "0.1.3"
@ -1377,21 +1502,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]]
name = "num-modular"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17bb261bf36fa7d83f4c294f834e91256769097b3cb505d44831e0a179ac647f"
[[package]]
name = "num-order"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "537b596b97c40fcf8056d153049eb22f481c17ebce72a513ec9286e4986d1bb6"
dependencies = [
"num-modular",
]
[[package]]
name = "num-traits"
version = "0.2.19"
@ -1445,6 +1555,15 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "parse-zoneinfo"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f2a05b18d44e2957b88f96ba460715e295bc1d7510468a2f3d3b44535d26c24"
dependencies = [
"regex",
]
[[package]]
name = "percent-encoding"
version = "2.3.1"
@ -1527,6 +1646,16 @@ dependencies = [
"phf_shared 0.8.0",
]
[[package]]
name = "phf_codegen"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a"
dependencies = [
"phf_generator 0.11.2",
"phf_shared 0.11.2",
]
[[package]]
name = "phf_generator"
version = "0.8.0"
@ -1906,7 +2035,7 @@ dependencies = [
"log",
"matches",
"phf 0.8.0",
"phf_codegen",
"phf_codegen 0.8.0",
"precomputed-hash",
"servo_arc",
"smallvec",
@ -2040,6 +2169,16 @@ dependencies = [
"autocfg",
]
[[package]]
name = "slug"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "882a80f72ee45de3cc9a5afeb2da0331d58df69e4e7d8eeb5d3c7784ae67e724"
dependencies = [
"deunicode",
"wasm-bindgen",
]
[[package]]
name = "smallvec"
version = "1.13.2"
@ -2107,6 +2246,28 @@ dependencies = [
"syn 2.0.87",
]
[[package]]
name = "tera"
version = "1.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab9d851b45e865f178319da0abdbfe6acbc4328759ff18dafc3a41c16b4cd2ee"
dependencies = [
"chrono",
"chrono-tz",
"globwalk",
"humansize",
"lazy_static",
"percent-encoding",
"pest",
"pest_derive",
"rand 0.8.5",
"regex",
"serde",
"serde_json",
"slug",
"unic-segment",
]
[[package]]
name = "thin-slice"
version = "0.1.1"
@ -2321,6 +2482,56 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"
[[package]]
name = "unic-char-property"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221"
dependencies = [
"unic-char-range",
]
[[package]]
name = "unic-char-range"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc"
[[package]]
name = "unic-common"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc"
[[package]]
name = "unic-segment"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4ed5d26be57f84f176157270c112ef57b86debac9cd21daaabbe56db0f88f23"
dependencies = [
"unic-ucd-segment",
]
[[package]]
name = "unic-ucd-segment"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2079c122a62205b421f499da10f3ee0f7697f012f55b675e002483c73ea34700"
dependencies = [
"unic-char-property",
"unic-char-range",
"unic-ucd-version",
]
[[package]]
name = "unic-ucd-version"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4"
dependencies = [
"unic-common",
]
[[package]]
name = "unicase"
version = "2.8.0"
@ -2505,6 +2716,15 @@ dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "windows-core"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
@ -2763,7 +2983,6 @@ dependencies = [
"fs_extra",
"futures",
"grass",
"handlebars",
"hotwatch",
"itertools",
"lol_html",
@ -2774,6 +2993,7 @@ dependencies = [
"rss",
"serde",
"serde_yml",
"tera",
"time",
"tokio",
"url",

View file

@ -10,7 +10,6 @@ eyre = "0.6"
fs_extra = "1.2"
futures = {version = "0.3", optional = true}
grass = {version = "0.13", default-features = false}
handlebars = "6"
hotwatch = {version = "0.5", optional = true}
itertools = "0.13"
lol_html = "2"
@ -24,6 +23,7 @@ rayon = "1"
rss = {version = "2", features = ["validation"]}
serde = {version = "1", features = ["derive"]}
serde_yml = "0.0.12"
tera = "1"
time = {version = "0.3", features = ["serde-human-readable"]}
tokio = {version = "1.10", features = [
"macros",

View file

@ -9,9 +9,9 @@ resources:
source_path: blog
output_path_short: blog
output_path_long: blog
resource_template: blog-post
resource_list_template: blog-list
rss_template: rss/blog-post
resource_template: blog-post.tera
resource_list_template: blog-list.tera
rss_template: rss/blog-post.tera
rss_title: zyl's blog
rss_description: feed of recent blog posts on zyl's website.
list_title: blog
@ -22,9 +22,9 @@ resources:
source_path: images
output_path_short: i
output_path_long: images
resource_template: image
resource_list_template: images
rss_template: rss/image
resource_template: image.tera
resource_list_template: images.tera
rss_template: rss/image.tera
rss_title: zyl's images
rss_description: feed of newly uploaded images from zyl's website.
list_title: images

View file

@ -8,5 +8,5 @@ embed:
description: click click click
extra:
name: basic
template: extras/click
template: extras/click.tera
---

View file

@ -1,7 +1,7 @@
---
extra:
name: resource-list-outside
template: extras/index-injection
template: extras/index-injection.tera
resource: blog
count: 3
---

View file

@ -1,3 +1,7 @@
{% macro badge(badge, url, alt) %}
<a href="{{url}}"><img src="/badges/{{badge}}" alt="{{alt}}"></a>
{% endmacro badge %}
<!DOCTYPE html>
<html lang="en">
@ -5,15 +9,15 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="referrer" content="no-referrer">
<link rel="stylesheet" href="/styles/index.css">
<title>{{title}}</title>
<title>{{ title }}</title>
<script type="text/javascript" src="/js/pet-me.js" defer></script>
{{{head}}}
{{#each scripts}}
<script type="text/javascript" src="{{this}}" defer></script>
{{/each}}
{{#each styles}}
<link rel="stylesheet" href="/styles/{{this}}">
{{/each}}
{{ head | safe }}
{% for script in scripts %}
<script type="text/javascript" src="{{script}}" defer></script>
{% endfor %}
{% for style in styles %}
<link rel="stylesheet" href="/styles/{{style}}">
{% endfor %}
</head>
<body>
@ -32,7 +36,7 @@
</header>
<div id="content">
<main class="page">
{{{page}}}
{% block content %}{{ page | safe }}{% endblock content %}
</main>
</div>
@ -42,10 +46,7 @@
bark bark awruff :3
<div class="badges">
{{#*inline "badge"}}
<a href="{{url}}"><img src="/badges/{{badge}}" alt="{{alt}}"></a>
{{/inline}}
{{> badge badge="transbian.png" url="https://badge.les.bi" alt="transgender and lesbian flags"}}
{{ self::badge(badge="transbian.png", url="https://badge.les.bi", alt="transgender and lesbian flags") }}
</div>
</footer>

View file

@ -1,8 +0,0 @@
<h1>{{title}}</h1>
<div class="link-list">
<ul>
{{#each links}}
<li><a href="{{this.link}}">{{this.title}}</a></li>
{{/each}}
</ul>
</div>

View file

@ -0,0 +1,8 @@
<h1>{{ title }}</h1>
<div class="link-list">
<ul>
{% for link in links %}
<li><a href="{{link.link}}">{{link.title}}</a></li>
{% endfor %}
</ul>
</div>

View file

@ -1,24 +1,24 @@
{{#if tag}}
{% if tag %}
<h1>blog posts tagged {{tag}}</h1>
<p><a href="/blog/">View all blog posts</a></p>
{{else}}
{% else %}
<h1>blog Posts</h1>
<p><a href="tags">view blog tags</a></p>
<p><a href="rss.xml">rss feed</a></p>
{{/if}}
{% endif %}
<h1>Page {{page}}/{{page_max}}</h1>
{{#if previous}}
{% if previous %}
<a href="./{{previous}}">previous page</a>
{{/if}}
{{#if next}}
{% endif %}
{% if next %}
<a href="./{{next}}">next page</a>
{{/if}}
{% endif %}
<div class="blog-post-list">
{{#each resources}}
{% for resource in resources %}
<div class="post">
<p class="title"><a href="/blog/{{id}}">{{title}}</a></p>
<p class="timestamp">{{timestamp}}</p>
<p class="short-desc">{{desc}}</p>
<p class="title"><a href="/blog/{{resource.id}}">{{resource.title}}</a></p>
<p class="timestamp">{{resource.timestamp}}</p>
<p class="short-desc">{{resource.desc}}</p>
</div>
{{/each}}
{% endfor %}
</div>

View file

@ -1,22 +1,22 @@
<div class="blog-post">
<h1 class="title">{{title}}</h1>
<span class="timestamp">published {{timestamp}}</span>
{{#if draft}}
{% if draft %}
<h2>DRAFT</h2>
{{/if}}
{% endif %}
<div class="header-image-wrapper">
<p class="short-desc">{{desc}}</p>
<img class="header-image" src="{{cdn_file}}" alt="{{header_image_alt}}"
style="object-fit: cover; object-position: 50% 50%">
</div>
<div class="content">
{{{content}}}
{{ content | safe }}
</div>
<hr />
<h3 class="tags-title">tags</h3>
<div class="post-tags">
{{#each tags}}
<a class="tag" href="/blog/tag/{{this}}">{{this}}</a>{{#unless @last}},{{/unless}}
{{/each}}
{% for tag in tags %}
<a class="tag" href="/blog/tag/{{tag}}">{{tag}}</a>{% if not loop.last %},{% endif %}
{% endfor %}
</div>
</div>

View file

@ -1,30 +0,0 @@
<div id="click">
<p>WARNING: no save mechanic is implemented yet!!</p>
<h1>click</h1>
<noscript>
<h1>javascript is required for the clicker game!!</h1>
</noscript>
<div class="resources">
{{#*inline "resource"}}
<span class="resource">{{name}}</span><span id={{id}}>0</span> <span>(<span
id="{{id}}-per-second">0</span>/s)</span>
{{/inline}}
{{> resource id="pets" name="pets"}}
{{> resource id="barks" name="barks"}}
{{> resource id="kisses" name="kisses"}}
</div>
<button id="barker">bark</button>
<div class="tools">
{{#*inline "tool"}}
<div class="tool" data-tool={{id}}>
<p class="name">{{name}} (<span class="count">0</span>, lvl <span class="level">1</span>)</p>
<p class="description">{{description}}</p>
<button class="buy">buy</button> <button class="upgrade">upgrade</button>
</div>
{{/inline}}
{{> tool id="hand" name="hand" description="don't bite the hand that pets you"}}
{{> tool id="puppy" name="puppy" description="arf arf wruff :3"}}
{{> tool id="foodBowl" name="food bowl" description="more food for more barking"}}
{{> tool id="kisser" name="kisser wow" description="someone to kiss all those poor puppies,,"}}
</div>
</div>

View file

@ -0,0 +1,31 @@
{% macro resource(id, name) %}
<span class="resource">{{name}}</span><span id={{id}}>0</span> <span>(<span id="{{id}}-per-second">0</span>/s)</span>
{% endmacro resource %}
{% macro tool(id, name, description) %}
<div class="tool" data-tool={{id}}>
<p class="name">{{name}} (<span class="count">0</span>, lvl <span class="level">1</span>)</p>
<p class="description">{{description}}</p>
<button class="buy">buy</button> <button class="upgrade">upgrade</button>
</div>
{% endmacro tool %}
<div id="click">
<p>WARNING: no save mechanic is implemented yet!!</p>
<h1>click</h1>
<noscript>
<h1>javascript is required for the clicker game!!</h1>
</noscript>
<div class="resources">
{{ self::resource(id="pets", name="pets") }}
{{ self::resource(id="barks", name="barks") }}
{{ self::resource(id="kisses", name="kisses") }}
</div>
<button id="barker">bark</button>
<div class="tools">
{{ self::tool(id="hand", name="hand", description="don't bite the hand that pets you") }}
{{ self::tool(id="puppy", name="puppy", description="arf arf wruff :3") }}
{{ self::tool(id="foodBowl", name="food bowl", description="more food for more barking") }}
{{ self::tool(id="kisser", name="kisser wow", description="someone to kiss all those poor puppies,,") }}
</div>
</div>

View file

@ -1,13 +0,0 @@
<hr />
<div class="index-info">
<h3>most recent blog posts</h3>
<div class="blog-post-list">
{{#each resources}}
<div class="post">
<p class="title"><a href="/blog/{{id}}">{{title}}</a></p>
<p class="timestamp">{{timestamp}}</p>
<p class="short-desc">{{desc}}</p>
</div>
{{/each}}
</div>
</div>

View file

@ -0,0 +1,13 @@
<hr />
<div class="index-info">
<h3>most recent blog posts</h3>
<div class="blog-post-list">
{% for resource in resources %}
<div class="post">
<p class="title"><a href="/blog/{{resource.id}}">{{resource.title}}</a></p>
<p class="timestamp">{{resource.timestamp}}</p>
<p class="short-desc">{{resource.desc}}</p>
</div>
{% endfor %}
</div>
</div>

View file

@ -2,12 +2,12 @@
<h1 class="title">{{title}}</h1>
<span class="timestamp">published {{timestamp}}</span>
<img class="image-actual" src="{{cdn_file}}" alt="{{alt}}">
{{{content}}}
{{ content | safe }}
<p><a href="{{cdn_file}}">view full size image</a></p>
<h3 class="tags-title">tags</h3>
<div class="image-tags">
{{#each tags}}
<a class="tag" href="/i/tag/{{this}}/">{{this}}</a>{{#unless @last}},{{/unless}}
{{/each}}
{% for tag in tags %}
<a class="tag" href="/i/tag/{{tag}}/">{{tag}}</a>{% if not loop.last %},{% endif %}
{% endfor %}
</div>
</div>

View file

@ -1,23 +1,23 @@
{{#if tag}}
{% if tag %}
<h1>images tagged {{tag}}</h1>
<p><a href="/images/">view all images</a></p>
{{else}}
{% else %}
<h1>images</h1>
<p><a href="/i/tags">view image tags</a></p>
<p><a href="rss.xml">rss feed</a></p>
{{/if}}
{% endif %}
<h3>page {{page}}/{{page_max}}</h3>
{{#if previous}}
{% if previous %}
<a href="./{{previous}}">previous page</a>
{{/if}}
{{#if next}}
{% endif %}
{% if next %}
<a href="./{{next}}">next page</a>
{{/if}}
{% endif %}
<div class="images-list">
{{#each resources}}
<a class="image" href="/i/{{id}}">
<img class="image-actual" src="{{cdn_file}}" alt="{{alt}}">
<span class="title">{{title}}</span>
{% for resource in resources %}
<a class="image" href="/i/{{resource.id}}">
<img class="image-actual" src="{{resource.cdn_file}}" alt="{{resource.alt}}">
<span class="title">{{resource.title}}</span>
</a>
{{/each}}
{% endfor %}
</div>

View file

@ -1 +0,0 @@
<div>{{{source}}}</div>

View file

@ -0,0 +1 @@
<div>{{ desc | safe }}</div>

View file

@ -1 +0,0 @@
<img src="{{src}}" alt="{{alt}}">

View file

@ -0,0 +1 @@
<img src="{{cdn_file}}" alt="{{alt}}">

View file

@ -3,10 +3,10 @@
use std::{collections::HashMap, path::PathBuf};
use eyre::{eyre, Context, OptionExt};
use handlebars::Handlebars;
use lol_html::{element, html_content::ContentType, HtmlRewriter, Settings};
use pulldown_cmark::{Options, Parser};
use serde::Serialize;
use tera::Tera;
use url::Url;
use crate::{resource::ResourceBuilder, util, PageMetadata, Site, ROOT_PATH, SASS_PATH};
@ -30,9 +30,9 @@ struct TemplateData<'a, T> {
}
/// Struct used to build the site.
pub struct SiteBuilder<'a> {
pub struct SiteBuilder {
/// The Handlebars registry used to render templates.
pub(crate) reg: Handlebars<'a>,
pub(crate) tera: Tera,
/// The site info used to build the site.
pub site: Site,
/// The path to the build directory.
@ -44,7 +44,7 @@ pub struct SiteBuilder<'a> {
pub resource_builders: HashMap<String, ResourceBuilder>,
}
impl<'a> SiteBuilder<'a> {
impl SiteBuilder {
/// Creates a new site builder.
pub fn new(site: Site, serving: bool) -> Self {
let mut build_path = match &site.config.build {
@ -55,8 +55,17 @@ impl<'a> SiteBuilder<'a> {
build_path = site.site_path.join("build");
}
let mut tera = Tera::new(
site.site_path
.join("templates/**/*.tera")
.to_str()
.expect("failed to convert path to string"),
)
.expect("failed to create tera instance");
tera.autoescape_on(vec![".tera"]);
Self {
reg: Handlebars::new(),
tera,
resource_builders: HashMap::new(),
site,
build_path,
@ -66,6 +75,7 @@ impl<'a> SiteBuilder<'a> {
/// Prepares the site builder for use and sets up the build directory.
pub fn prepare(mut self) -> eyre::Result<Self> {
self.tera.full_reload()?;
if self.build_path.exists() {
for entry in self.build_path.read_dir()? {
let path = &entry?.path();
@ -82,12 +92,6 @@ impl<'a> SiteBuilder<'a> {
std::fs::create_dir(&self.build_path).wrap_err("Failed to create build directory")?;
}
for (template_name, template_path) in &self.site.template_index {
self.reg
.register_template_file(template_name, template_path)
.wrap_err("Failed to register template file")?;
}
let root_path = self.site.site_path.join(ROOT_PATH);
if root_path.exists() {
for entry in walkdir::WalkDir::new(&root_path) {
@ -272,16 +276,18 @@ impl<'a> SiteBuilder<'a> {
embed.build()
});
let out = self.reg.render(
&page_metadata.template.unwrap_or_else(|| "base".to_string()),
&TemplateData {
let out = self.tera.render(
&page_metadata
.template
.unwrap_or_else(|| "base.tera".to_string()),
&tera::Context::from_serialize(TemplateData {
page: page_html,
title: &title,
head,
scripts: &page_metadata.scripts,
styles: &page_metadata.styles,
extra_data,
},
})?,
)?;
// Modify HTML output

View file

@ -30,7 +30,7 @@ impl Extra {
match self {
Self::Basic => {
let data: BasicData = serde_yml::from_value(data.inner.clone())?;
let content = builder.reg.render(&data.template, &())?;
let content = builder.tera.render(&data.template, &tera::Context::new())?;
append_to(&page, &content, "main.page")
}
Self::HtmlModification(f) => (f)(page, builder, data),
@ -91,9 +91,9 @@ fn resource_list_outside(
let data: ResourceListData = serde_yml::from_value(data.inner.clone())?;
let resource_list = builder.reg.render(
let resource_list = builder.tera.render(
&data.template,
&ResourceListTemplateData {
&tera::Context::from_serialize(ResourceListTemplateData {
resources: builder
.resource_builders
.get(&data.resource)
@ -107,7 +107,7 @@ fn resource_list_outside(
timestamp: v.timestamp,
})
.collect(),
},
})?,
)?;
append_to(&page, &resource_list, "#content")

View file

@ -29,7 +29,10 @@ pub fn render_basic_link_list(
title: &str,
) -> eyre::Result<String> {
let data = LinkTemplateData { links, title };
let out = builder.reg.render("basic-link-list", &data)?;
let out = builder.tera.render(
"basic-link-list.tera",
&tera::Context::from_serialize(data)?,
)?;
let out = builder.build_page_raw(
PageMetadata {
title: Some(title.to_owned()),

View file

@ -258,7 +258,10 @@ impl ResourceBuilder {
id,
timestamp: resource.timestamp,
};
builder.reg.render(&self.config.resource_template, &data)?
builder.tera.render(
&self.config.resource_template,
&tera::Context::from_serialize(data)?,
)?
};
let out = builder.build_page_raw_with_extra_data(
@ -341,7 +344,10 @@ impl ResourceBuilder {
previous,
next,
};
let out = builder.reg.render(&config.resource_list_template, &data)?;
let out = builder.tera.render(
&config.resource_list_template,
&tera::Context::from_serialize(data)?,
)?;
let out = builder.build_page_raw(
PageMetadata {
title: Some(title.to_owned()),
@ -437,9 +443,10 @@ impl ResourceBuilder {
))
.description(resource.resource.desc.clone())
.pub_date(Some(resource.timestamp.format(&Rfc2822)?))
.content(Some(
builder.reg.render(&self.config.rss_template, &resource)?,
))
.content(Some(builder.tera.render(
&self.config.rss_template,
&tera::Context::from_serialize(resource)?,
)?))
.build(),
)
}

View file

@ -79,9 +79,8 @@ fn create(
if build {
builder.build_page(&page_name_str)?;
}
} else if let Ok(template_path) = relative_path.strip_prefix(TEMPLATES_PATH) {
let (_template_name, template_name_str) = get_name(template_path);
builder.refresh_template(&template_name_str, path)?;
} else if let Ok(_template_path) = relative_path.strip_prefix(TEMPLATES_PATH) {
builder.tera.full_reload()?;
if build {
builder.site.build_all_pages(builder)?;
builder.build_all_resources()?;
@ -118,7 +117,7 @@ fn remove(builder: &mut SiteBuilder, path: &Path, relative_path: &Path) -> eyre:
} else if let Ok(template_path) = relative_path.strip_prefix(TEMPLATES_PATH) {
let (_template_name, template_name_str) = get_name(template_path);
builder.site.template_index.remove(&template_name_str);
builder.reg.unregister_template(&template_name_str);
builder.tera.full_reload()?;
builder
.site
.build_all_pages(builder)
@ -324,17 +323,3 @@ impl Site {
Ok(())
}
}
impl<'a> SiteBuilder<'a> {
/// Refreshes a template to ensure it's up to date.
pub fn refresh_template(
&mut self,
template_name: &str,
template_path: &Path,
) -> eyre::Result<()> {
self.reg
.register_template_file(template_name, template_path)?;
Ok(())
}
}