Compare commits
11 Commits
v0.4.0
...
d41b7610cd
| Author | SHA1 | Date | |
|---|---|---|---|
|
d41b7610cd
|
|||
|
587094185d
|
|||
|
c538b44f6b
|
|||
|
865387d021
|
|||
|
5e8d2e04e0
|
|||
|
266850dccf
|
|||
|
db3fa1b75f
|
|||
|
e83a9f3f51
|
|||
|
ad582caa5b
|
|||
|
f230d455f2
|
|||
|
ae73f21f67
|
55
.forgejo/workflows/build-conainer.yml
Normal file
55
.forgejo/workflows/build-conainer.yml
Normal file
@@ -0,0 +1,55 @@
|
||||
on:
|
||||
push:
|
||||
tags: "container-*"
|
||||
|
||||
env:
|
||||
REGISTRY: git.gay
|
||||
IMAGE_NAME: ${{ github.repository }}
|
||||
|
||||
# There is a single job in this workflow. It's configured to run on the latest
|
||||
# available version of Ubuntu.
|
||||
jobs:
|
||||
build-and-push-image:
|
||||
runs-on: elf
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: https://code.forgejo.org/actions/checkout@v4
|
||||
# Uses the `docker/login-action` action to log in to the Container
|
||||
# registry registry using the account and password that will publish the
|
||||
# packages. Once published, the packages are scoped to the account defined
|
||||
# here.
|
||||
- name: Log in to the Container registry
|
||||
uses: https://code.forgejo.org/docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
# This step uses [docker/metadata-action](https://code.forgejo.org/docker/metadata-action#about)
|
||||
# to extract tags and labels that will be applied to the specified image.
|
||||
# The `id` "meta" allows the output of this step to be referenced in a
|
||||
# subsequent step. The `images` value provides the base name for the tags
|
||||
# and labels.
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: https://code.forgejo.org/docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
latest
|
||||
# This step uses the `docker/build-push-action` action to build the image,
|
||||
# based on your repository's `Dockerfile`. If the build succeeds, it
|
||||
# pushes the image to GitHub Packages.
|
||||
# It uses the `context` parameter to define the build's context as the set
|
||||
# of files located in the specified path. For more information, see
|
||||
# "[Usage](https://code.forgejo.org/docker/build-push-action#usage)" in
|
||||
# the README of the `docker/build-push-action` repository.
|
||||
# It uses the `tags` and `labels` parameters to tag and label the image
|
||||
# with the output from the "meta" step.
|
||||
- name: Build and push Docker image
|
||||
uses: https://code.forgejo.org/docker/build-push-action@v6
|
||||
with:
|
||||
# the path to the container files (the `Dockerfile`)
|
||||
context: docker
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
/target
|
||||
/html
|
||||
/src/version.rs
|
||||
/webTemplate-*
|
||||
|
||||
271
Cargo.lock
generated
271
Cargo.lock
generated
@@ -4,13 +4,63 @@ version = 4
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "arraydeque"
|
||||
version = "0.5.1"
|
||||
@@ -19,15 +69,61 @@ checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.9.1"
|
||||
version = "2.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
||||
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.1"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
|
||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e34525d5bbbd55da2bb745d34b36121baac88d07619a9a09cfcf4a6c0832785"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59a20016a20a3da95bef50ec7238dbd09baeef4311dcdd38ec15aba69812fb61"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.7.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3e64b0cc0439b12df2fa678eae89a1c56a529fd067a9115f7827f1fffd22b32"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
@@ -46,18 +142,18 @@ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
|
||||
|
||||
[[package]]
|
||||
name = "getopts"
|
||||
version = "0.2.23"
|
||||
version = "0.2.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cba6ae63eb948698e300f645f87c70f76630d505f23b8907cf1e193ee85048c1"
|
||||
checksum = "cfe4fbac503b8d1f88e6676011885f34b7174f46e59956bba534ba83abded4df"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.15.4"
|
||||
version = "0.15.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5"
|
||||
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
|
||||
dependencies = [
|
||||
"foldhash",
|
||||
]
|
||||
@@ -72,16 +168,28 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.5"
|
||||
version = "2.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
|
||||
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
||||
|
||||
[[package]]
|
||||
name = "memo-map"
|
||||
@@ -91,9 +199,9 @@ checksum = "38d1115007560874e373613744c6fba374c17688327a71c1476d1a5954cc857b"
|
||||
|
||||
[[package]]
|
||||
name = "minijinja"
|
||||
version = "2.11.0"
|
||||
version = "2.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e60ac08614cc09062820e51d5d94c2fce16b94ea4e5003bb81b99a95f84e876"
|
||||
checksum = "b479616bb6f0779fb0f3964246beda02d4b01144e1b0d5519616e012ccc2a245"
|
||||
dependencies = [
|
||||
"memo-map",
|
||||
"self_cell",
|
||||
@@ -102,10 +210,16 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.95"
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
|
||||
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@@ -113,8 +227,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "pulldown-cmark"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e8bbe1a966bd2f362681a44f6edce3c2310ac21e4d5067a6e7ec396297a6ea0"
|
||||
source = "git+https://git.gay/LailaTheElf/pulldown-cmark.git?branch=feature%2FeventTree#2300d0db6541279c41928b44d12eac510ecc3199"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"getopts",
|
||||
@@ -127,23 +240,22 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "pulldown-cmark-escape"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae"
|
||||
source = "git+https://git.gay/LailaTheElf/pulldown-cmark.git?branch=feature%2FeventTree#2300d0db6541279c41928b44d12eac510ecc3199"
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.40"
|
||||
version = "1.0.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.1"
|
||||
version = "1.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
||||
checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@@ -153,9 +265,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.9"
|
||||
version = "0.4.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
||||
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@@ -164,36 +276,40 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.5"
|
||||
version = "0.8.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
|
||||
|
||||
[[package]]
|
||||
name = "self_cell"
|
||||
version = "1.2.0"
|
||||
version = "1.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f7d95a54511e0c7be3f51e8867aa8cf35148d7b9445d44de2f943e2b206e749"
|
||||
checksum = "b12e76d157a900eb52e81bc6e9f3069344290341720e9178cde2407113ac8d89"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.219"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
|
||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.219"
|
||||
version = "1.0.228"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -202,21 +318,28 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.141"
|
||||
version = "1.0.149"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3"
|
||||
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.104"
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.114"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -225,26 +348,33 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.8.1"
|
||||
version = "2.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539"
|
||||
checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c"
|
||||
checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "webTemplate"
|
||||
version = "0.4.0"
|
||||
version = "0.5.0-2"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"hashlink",
|
||||
"minijinja",
|
||||
"pulldown-cmark",
|
||||
@@ -253,12 +383,33 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yaml-rust2"
|
||||
version = "0.10.3"
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ce2a4ff45552406d02501cea6c18d8a7e50228e7736a872951fe2fe75c91be7"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yaml-rust2"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2462ea039c445496d8793d052e13787f2b90e750b833afee748e601c17621ed9"
|
||||
dependencies = [
|
||||
"arraydeque",
|
||||
"encoding_rs",
|
||||
"hashlink",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02aae0f83f69aafc94776e879363e9771d7ecbffe2c7fbb6c14c5e00dfe88439"
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
[package]
|
||||
name = "webTemplate"
|
||||
version = "0.4.0"
|
||||
version = "0.5.0-2"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.55", features = ["derive"] }
|
||||
hashlink = "0.10.0"
|
||||
minijinja = { version = "2.10.2", features = ["loader", "builtins", "json"] }
|
||||
pulldown-cmark = { version = "0.13.0", features = ["serde"] }
|
||||
regex = "1.11.1"
|
||||
yaml-rust2 = "0.10.2"
|
||||
|
||||
[dependencies.pulldown-cmark]
|
||||
git = "https://git.gay/LailaTheElf/pulldown-cmark.git"
|
||||
branch = "feature/eventTree"
|
||||
features = ["serde"]
|
||||
|
||||
9
build.sh
9
build.sh
@@ -1,5 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm webTemplate-*
|
||||
|
||||
set -e
|
||||
|
||||
version="$(cat Cargo.toml | grep '^version' | sed -e 's/^.*"\([^"]*\)".*$/\1/')"
|
||||
commit="$(git show --oneline -s | sed -e 's/ .*$//')"
|
||||
dirty="$(test "$(git diff --shortstat 2> /dev/null | tail -n1)" == "" || echo -n "_drity" )"
|
||||
echo "pub const VERSION: &'static str = \"${version} (${commit}${dirty})\";" >src/version.rs
|
||||
|
||||
cross build --target aarch64-unknown-linux-gnu --release
|
||||
cargo build --release
|
||||
|
||||
|
||||
6
docker/000-default.conf
Normal file
6
docker/000-default.conf
Normal file
@@ -0,0 +1,6 @@
|
||||
<VirtualHost *:80>
|
||||
ServerAdmin webmaster@localhost
|
||||
DocumentRoot /var/www/public
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||
</VirtualHost>
|
||||
19
docker/Dockerfile
Normal file
19
docker/Dockerfile
Normal file
@@ -0,0 +1,19 @@
|
||||
FROM php:apache
|
||||
|
||||
RUN mkdir -p /var/www
|
||||
WORKDIR /var/www
|
||||
|
||||
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
|
||||
COPY apache2.conf /etc/apache2/apache2.conf
|
||||
RUN apt-get update && apt-get install -y curl && \
|
||||
a2enmod rewrite
|
||||
|
||||
COPY build.sh /var/www/build.sh
|
||||
RUN curl https://gitea.finnvanreenen.nl/LailaTheElf/webTemplate/releases/download/v0.4.0/webTemplate-x86_64 \
|
||||
--output /var/www/webtemplate && \
|
||||
chmod +x /var/www/webtemplate && \
|
||||
chmod +x /var/www/build.sh
|
||||
|
||||
VOLUME /var/www/src
|
||||
|
||||
CMD ["/var/www/build.sh"]
|
||||
225
docker/apache2.conf
Normal file
225
docker/apache2.conf
Normal file
@@ -0,0 +1,225 @@
|
||||
# This is the main Apache server configuration file. It contains the
|
||||
# configuration directives that give the server its instructions.
|
||||
# See http://httpd.apache.org/docs/2.4/ for detailed information about
|
||||
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
|
||||
# hints.
|
||||
#
|
||||
#
|
||||
# Summary of how the Apache 2 configuration works in Debian:
|
||||
# The Apache 2 web server configuration in Debian is quite different to
|
||||
# upstream's suggested way to configure the web server. This is because Debian's
|
||||
# default Apache2 installation attempts to make adding and removing modules,
|
||||
# virtual hosts, and extra configuration directives as flexible as possible, in
|
||||
# order to make automating the changes and administering the server as easy as
|
||||
# possible.
|
||||
|
||||
# It is split into several files forming the configuration hierarchy outlined
|
||||
# below, all located in the /etc/apache2/ directory:
|
||||
#
|
||||
# /etc/apache2/
|
||||
# |-- apache2.conf
|
||||
# | `-- ports.conf
|
||||
# |-- mods-enabled
|
||||
# | |-- *.load
|
||||
# | `-- *.conf
|
||||
# |-- conf-enabled
|
||||
# | `-- *.conf
|
||||
# `-- sites-enabled
|
||||
# `-- *.conf
|
||||
#
|
||||
#
|
||||
# * apache2.conf is the main configuration file (this file). It puts the pieces
|
||||
# together by including all remaining configuration files when starting up the
|
||||
# web server.
|
||||
#
|
||||
# * ports.conf is always included from the main configuration file. It is
|
||||
# supposed to determine listening ports for incoming connections which can be
|
||||
# customized anytime.
|
||||
#
|
||||
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
|
||||
# directories contain particular configuration snippets which manage modules,
|
||||
# global configuration fragments, or virtual host configurations,
|
||||
# respectively.
|
||||
#
|
||||
# They are activated by symlinking available configuration files from their
|
||||
# respective *-available/ counterparts. These should be managed by using our
|
||||
# helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
|
||||
# their respective man pages for detailed information.
|
||||
#
|
||||
# * The binary is called apache2. Due to the use of environment variables, in
|
||||
# the default configuration, apache2 needs to be started/stopped with
|
||||
# /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
|
||||
# work with the default configuration.
|
||||
|
||||
|
||||
# Global configuration
|
||||
#
|
||||
|
||||
#
|
||||
# ServerRoot: The top of the directory tree under which the server's
|
||||
# configuration, error, and log files are kept.
|
||||
#
|
||||
# NOTE! If you intend to place this on an NFS (or otherwise network)
|
||||
# mounted filesystem then please read the Mutex documentation (available
|
||||
# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
|
||||
# you will save yourself a lot of trouble.
|
||||
#
|
||||
# Do NOT add a slash at the end of the directory path.
|
||||
#
|
||||
#ServerRoot "/etc/apache2"
|
||||
|
||||
#
|
||||
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
|
||||
#
|
||||
#Mutex file:${APACHE_LOCK_DIR} default
|
||||
|
||||
#
|
||||
# The directory where shm and other runtime files will be stored.
|
||||
#
|
||||
|
||||
DefaultRuntimeDir ${APACHE_RUN_DIR}
|
||||
|
||||
#
|
||||
# PidFile: The file in which the server should record its process
|
||||
# identification number when it starts.
|
||||
# This needs to be set in /etc/apache2/envvars
|
||||
#
|
||||
PidFile ${APACHE_PID_FILE}
|
||||
|
||||
#
|
||||
# Timeout: The number of seconds before receives and sends time out.
|
||||
#
|
||||
Timeout 300
|
||||
|
||||
#
|
||||
# KeepAlive: Whether or not to allow persistent connections (more than
|
||||
# one request per connection). Set to "Off" to deactivate.
|
||||
#
|
||||
KeepAlive On
|
||||
|
||||
#
|
||||
# MaxKeepAliveRequests: The maximum number of requests to allow
|
||||
# during a persistent connection. Set to 0 to allow an unlimited amount.
|
||||
# We recommend you leave this number high, for maximum performance.
|
||||
#
|
||||
MaxKeepAliveRequests 100
|
||||
|
||||
#
|
||||
# KeepAliveTimeout: Number of seconds to wait for the next request from the
|
||||
# same client on the same connection.
|
||||
#
|
||||
KeepAliveTimeout 5
|
||||
|
||||
|
||||
# These need to be set in /etc/apache2/envvars
|
||||
User ${APACHE_RUN_USER}
|
||||
Group ${APACHE_RUN_GROUP}
|
||||
|
||||
#
|
||||
# HostnameLookups: Log the names of clients or just their IP addresses
|
||||
# e.g., www.apache.org (on) or 204.62.129.132 (off).
|
||||
# The default is off because it'd be overall better for the net if people
|
||||
# had to knowingly turn this feature on, since enabling it means that
|
||||
# each client request will result in AT LEAST one lookup request to the
|
||||
# nameserver.
|
||||
#
|
||||
HostnameLookups Off
|
||||
|
||||
# ErrorLog: The location of the error log file.
|
||||
# If you do not specify an ErrorLog directive within a <VirtualHost>
|
||||
# container, error messages relating to that virtual host will be
|
||||
# logged here. If you *do* define an error logfile for a <VirtualHost>
|
||||
# container, that host's errors will be logged there and not here.
|
||||
#
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
|
||||
#
|
||||
# LogLevel: Control the severity of messages logged to the error_log.
|
||||
# Available values: trace8, ..., trace1, debug, info, notice, warn,
|
||||
# error, crit, alert, emerg.
|
||||
# It is also possible to configure the log level for particular modules, e.g.
|
||||
# "LogLevel info ssl:warn"
|
||||
#
|
||||
LogLevel warn
|
||||
|
||||
# Include module configuration:
|
||||
IncludeOptional mods-enabled/*.load
|
||||
IncludeOptional mods-enabled/*.conf
|
||||
|
||||
# Include list of ports to listen on
|
||||
Include ports.conf
|
||||
|
||||
|
||||
# Sets the default security model of the Apache2 HTTPD server. It does
|
||||
# not allow access to the root filesystem outside of /usr/share and /var/www.
|
||||
# The former is used by web applications packaged in Debian,
|
||||
# the latter may be used for local directories served by the web server. If
|
||||
# your system is serving content from a sub-directory in /srv you must allow
|
||||
# access here, or in any related virtual host.
|
||||
<Directory />
|
||||
Options FollowSymLinks
|
||||
AllowOverride None
|
||||
Require all denied
|
||||
</Directory>
|
||||
|
||||
<Directory /usr/share>
|
||||
AllowOverride None
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
<Directory /var/www/>
|
||||
Options Indexes FollowSymLinks
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
#<Directory /srv/>
|
||||
# Options Indexes FollowSymLinks
|
||||
# AllowOverride None
|
||||
# Require all granted
|
||||
#</Directory>
|
||||
|
||||
|
||||
|
||||
|
||||
# AccessFileName: The name of the file to look for in each directory
|
||||
# for additional configuration directives. See also the AllowOverride
|
||||
# directive.
|
||||
#
|
||||
AccessFileName .htaccess
|
||||
|
||||
#
|
||||
# The following lines prevent .htaccess and .htpasswd files from being
|
||||
# viewed by Web clients.
|
||||
#
|
||||
<FilesMatch "^\.ht">
|
||||
Require all denied
|
||||
</FilesMatch>
|
||||
|
||||
|
||||
#
|
||||
# The following directives define some format nicknames for use with
|
||||
# a CustomLog directive.
|
||||
#
|
||||
# These deviate from the Common Log Format definitions in that they use %O
|
||||
# (the actual bytes sent including headers) instead of %b (the size of the
|
||||
# requested file), because the latter makes it impossible to detect partial
|
||||
# requests.
|
||||
#
|
||||
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
|
||||
# Use mod_remoteip instead.
|
||||
#
|
||||
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
|
||||
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
|
||||
LogFormat "%h %l %u %t \"%r\" %>s %O" common
|
||||
LogFormat "%{Referer}i -> %U" referer
|
||||
LogFormat "%{User-agent}i" agent
|
||||
|
||||
# Include of directories ignores editors' and dpkg's backup files,
|
||||
# see README.Debian for details.
|
||||
|
||||
# Include generic snippets of statements
|
||||
IncludeOptional conf-enabled/*.conf
|
||||
|
||||
# Include the virtual host configurations:
|
||||
IncludeOptional sites-enabled/*.conf
|
||||
5
docker/build.sh
Normal file
5
docker/build.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
/var/www/webtemplate --output=/var/www/public --src=/var/www/src
|
||||
|
||||
apache2-foreground
|
||||
192
src/main.rs
192
src/main.rs
@@ -1,163 +1,105 @@
|
||||
use std::{path::Path, fs, env};
|
||||
use minijinja::Environment;
|
||||
use std::{convert::Infallible, fs, path::Path};
|
||||
use clap::Parser;
|
||||
|
||||
mod render;
|
||||
use render::{Renderer, IndexItem, build_jinja_env, Template};
|
||||
use render::{Renderer, IndexItem};
|
||||
|
||||
const SRC_PATH: &'static str = "./src/";
|
||||
const OUT_PATH: &'static str = "./html/";
|
||||
mod version;
|
||||
use version::VERSION;
|
||||
|
||||
fn render_index(
|
||||
fn render_page(
|
||||
page: &IndexItem,
|
||||
out_path: &Path,
|
||||
index: &IndexItem,
|
||||
index: &Renderer,
|
||||
cur_path: &Path,
|
||||
site_index: &Renderer,
|
||||
templates: Option<Vec<Box<Template>>>,
|
||||
jinja_env: Option<&Environment>
|
||||
) {
|
||||
let dest_path: &Path = &cur_path.join(&index.friendly);
|
||||
// println!("dest_path: {:?}", dest_path);
|
||||
|
||||
let templates = match templates {
|
||||
Some(template) => template,
|
||||
None => Template::index(&site_index.path.join("templates")),
|
||||
};
|
||||
|
||||
let jinja_env = match jinja_env {
|
||||
Some(env) => env,
|
||||
None => &build_jinja_env(templates.clone()),
|
||||
};
|
||||
|
||||
match &index.src {
|
||||
Some(src) => {
|
||||
// a source file is available. try to render it
|
||||
|
||||
let friendly = match index.friendly.len() {
|
||||
0 => String::from("index"),
|
||||
_ => index.friendly.clone()
|
||||
};
|
||||
|
||||
if !index.is_asset {
|
||||
// find template
|
||||
let templ: Option<Template> = {
|
||||
let mut out = None;
|
||||
for templ in templates.clone() {
|
||||
if let Some(templ) = templ.search(index.template.clone()) {
|
||||
out = Some(templ);
|
||||
break;
|
||||
}
|
||||
}
|
||||
out
|
||||
let friendly = match page.friendly.len() {
|
||||
0 => "index",
|
||||
_ => &page.friendly
|
||||
};
|
||||
|
||||
if let Some(src) = &page.src {
|
||||
if !page.is_asset {
|
||||
// get output file extention
|
||||
let extention = match index.target_extention.len() {
|
||||
0 => match templ {
|
||||
Some(templ) => templ.extention,
|
||||
None => String::from("html")
|
||||
}
|
||||
_ => index.target_extention.clone()
|
||||
let extention = match page.target_extention.len() {
|
||||
0 => String::from("html"),
|
||||
_ => page.target_extention.clone()
|
||||
};
|
||||
let dest_path: &Path = &cur_path.join(format!("{}.{}", friendly, extention));
|
||||
// render the content
|
||||
println!("INFO: render {}", dest_path.to_str().unwrap());
|
||||
match site_index.render_page(index, &site_index.site, jinja_env) {
|
||||
Some(content) => {
|
||||
let _ = fs::write(dest_path, content);
|
||||
match index.render_page(page) {
|
||||
Ok(content) => {
|
||||
let _: Result<(), Infallible> = fs::write(dest_path, content).or_else(|e|{
|
||||
println!("ERROR during writing: {:?}", e);
|
||||
Ok(())
|
||||
});
|
||||
},
|
||||
Err(e) => {
|
||||
println!("ERROR during rendering: {:?}", e);
|
||||
},
|
||||
None => todo!(),
|
||||
};
|
||||
}
|
||||
else {
|
||||
// file is an asset, no rendering done for assets
|
||||
let dest_path: &Path = &cur_path.join(friendly);
|
||||
println!("INFO: copy {}", dest_path.to_str().unwrap());
|
||||
let _ = fs::copy(src, dest_path);
|
||||
match dest_path.to_str() {
|
||||
Some(dest_path_str) => {
|
||||
println!("INFO: copy {}", dest_path_str);
|
||||
let _: Result<u64, Infallible> = fs::copy(src, dest_path).or_else(|e|{
|
||||
println!("ERROR during copying: {:?}", e);
|
||||
Ok(0)
|
||||
});
|
||||
}
|
||||
},
|
||||
None => {
|
||||
let _ = fs::create_dir(dest_path);
|
||||
},
|
||||
};
|
||||
|
||||
for page in &index.sub_pages {
|
||||
render_index(out_path, page, dest_path, &site_index, Some(templates.clone()), Some(&jinja_env));
|
||||
println!("ERROR: dest path is None for asset: {}", friendly);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn usage() {
|
||||
println!("webtemplate [--output=<dir>] [--src=<dir>]");
|
||||
for page in page.sub_pages.iter() {
|
||||
render_page(page, out_path, &index, cur_path);
|
||||
}
|
||||
}
|
||||
|
||||
/// render static website using markdown and jinja templates
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(about, long_about = None)]
|
||||
struct Args {
|
||||
/// path output directory
|
||||
#[arg(short, long, default_value = "./public_html")]
|
||||
output: String,
|
||||
|
||||
/// path source directory
|
||||
#[arg(short, long, default_value = "./src")]
|
||||
source: String,
|
||||
|
||||
/// print version
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
version: bool
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
let mut src_path_str: String = SRC_PATH.to_string();
|
||||
let mut out_path_str: String = OUT_PATH.to_string();
|
||||
|
||||
for arg in env::args() {
|
||||
if arg.starts_with("--") {
|
||||
let mut parts = arg.split('=');
|
||||
let option: String = match parts.next() {
|
||||
None => {
|
||||
println!("WARN: argument parsing: faild to split argument");
|
||||
continue;
|
||||
},
|
||||
Some(str) => {
|
||||
let mut str = String::from(str);
|
||||
str.remove(0);
|
||||
str.remove(0);
|
||||
str
|
||||
}
|
||||
};
|
||||
let value = match parts.next() {
|
||||
None => None,
|
||||
Some(str) => Some(String::from(str))
|
||||
};
|
||||
|
||||
match option.as_str() {
|
||||
"output" => {
|
||||
if let Some(value) = value {
|
||||
out_path_str = value;
|
||||
} else {
|
||||
println!("ERROR: no value given for output");
|
||||
usage();
|
||||
let args = Args::parse();
|
||||
if args.version {
|
||||
println!("version: {}", VERSION);
|
||||
return;
|
||||
}
|
||||
}
|
||||
"src" => {
|
||||
if let Some(value) = value {
|
||||
src_path_str = value;
|
||||
} else {
|
||||
println!("ERROR: no value given for output");
|
||||
usage();
|
||||
return;
|
||||
}
|
||||
}
|
||||
"help" => {
|
||||
usage();
|
||||
}
|
||||
_ => {
|
||||
println!("ERROR: invalid option {}", option);
|
||||
usage();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let src_path = Path::new(&src_path_str);
|
||||
let out_path = Path::new(&out_path_str);
|
||||
let src_path = Path::new(&args.source);
|
||||
let out_path = Path::new(&args.output);
|
||||
|
||||
// scan all pages, template, components, etc.
|
||||
let index = match Renderer::index(src_path) {
|
||||
// scan all pages adn templates
|
||||
let index = match Renderer::index(src_path).or_else::<Infallible, _>(|e| {
|
||||
panic!("PANIC: faild to index: {:?}", e);
|
||||
}).unwrap() {
|
||||
Some(index) => index,
|
||||
None => {
|
||||
println!("ERROR: src directory not found ({})", src_path_str);
|
||||
return;
|
||||
panic!("ERROR: src directory not found ({})", src_path.to_str().or(Some("Utf parse error")).unwrap());
|
||||
},
|
||||
};
|
||||
|
||||
// render website
|
||||
let _ = fs::create_dir_all(out_path);
|
||||
render_index(out_path, &index.site, out_path, &index, None, None);
|
||||
// render pages
|
||||
render_page(&index.site, out_path, &index, out_path);
|
||||
}
|
||||
|
||||
@@ -1,60 +1,46 @@
|
||||
mod index;
|
||||
mod parse_md;
|
||||
|
||||
use std::{collections::BTreeMap, fs, path::Path};
|
||||
use minijinja::{context, Environment, Value};
|
||||
use index::indexer;
|
||||
use parse_md::parse_md;
|
||||
use std::{collections::BTreeMap, fs, io::Error as IoError, path::Path};
|
||||
use minijinja::{Environment, Error as JinjaError, Value, context};
|
||||
use index::indexer::Error as IndexError;
|
||||
use yaml_rust2::Yaml;
|
||||
use crate::render::{index::indexer::split_params, parse_md::{Parser, Error as ParserError}};
|
||||
|
||||
pub use index::indexer::{IndexItem, Template};
|
||||
|
||||
pub fn build_jinja_env<'a>(templates: Vec<Box<indexer::Template>>) -> Environment<'a> {
|
||||
build_jinja_env_dir(templates)
|
||||
}
|
||||
fn build_jinja_env_dir<'a>(templates: Vec<Box<indexer::Template>>) -> Environment<'a> {
|
||||
let mut env: Environment = Environment::new();
|
||||
for template in templates {
|
||||
match template.src {
|
||||
Some(src) => {
|
||||
match env.add_template_owned(template.name.clone(), src) {
|
||||
Ok(_) => {},
|
||||
Err(err) => println!("ERROR: failt to add template \"{}\" ({err:?})", template.name),
|
||||
}
|
||||
},
|
||||
None => {
|
||||
for plate in template.sub_templates {
|
||||
if let Some(src) = plate.src {
|
||||
let name = format!("{}/{}", template.name.clone(), plate.name.clone());
|
||||
match env.add_template_owned(name.clone(), src) {
|
||||
Ok(_) => {}, //println!("template name: {name}"),
|
||||
Err(err) => println!("ERROR: failt to add template \"{name}\" ({err:?})"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
env
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
NoSrc,
|
||||
Io(IoError),
|
||||
Jinja(JinjaError),
|
||||
Indexer(IndexError),
|
||||
Parser(ParserError),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Renderer {
|
||||
// jinja_env: Environment<'a>,
|
||||
pub struct Renderer<'a> {
|
||||
pub site: IndexItem,
|
||||
pub path: Box<Path>
|
||||
templates: Vec<Template>,
|
||||
jinja_env: Environment<'a>,
|
||||
}
|
||||
impl Renderer {
|
||||
pub fn index(path: &Path) -> Option<Renderer> {
|
||||
if let Some(site_index) = IndexItem::index(&path) {
|
||||
Some(Renderer {
|
||||
impl<'a> Renderer<'a> {
|
||||
pub fn index(path: &Path) -> Result<Option<Renderer>, Error> {
|
||||
if let Some(site_index) = IndexItem::index(&path).or_else(|e| Err(Error::Indexer(e)))? {
|
||||
let templates = Template::index(&path.join("templates")).or_else(|e| Err(Error::Indexer(e)))?;
|
||||
let mut jinja_env = Environment::new();
|
||||
for tmpl in templates.iter() {
|
||||
tmpl.add_to_jinja_env(&mut jinja_env).or_else(|e| Err(Error::Jinja(e)))?;
|
||||
};
|
||||
Ok(Some(Renderer {
|
||||
site: site_index,
|
||||
path: Box::from(path)
|
||||
})
|
||||
templates,
|
||||
jinja_env,
|
||||
}))
|
||||
}
|
||||
else {
|
||||
None
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,30 +75,27 @@ impl Renderer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_page(&self, page: &IndexItem, index: &IndexItem, jinja_env: &Environment) -> Option<String> {
|
||||
pub fn render_page(&self, page: &IndexItem) -> Result<String, Error> {
|
||||
if page.src == None {
|
||||
return None;
|
||||
}
|
||||
match fs::read_to_string(page.src.as_ref().unwrap()) {
|
||||
Ok(content) => {
|
||||
let split = indexer::split_params(content);
|
||||
match parse_md(split.md, jinja_env) {
|
||||
Some(md) => {
|
||||
let template = jinja_env.get_template(&page.template).unwrap();
|
||||
return Err(Error::NoSrc);
|
||||
};
|
||||
let content = fs::read_to_string(page.src.as_ref().unwrap()).or_else(|e| Err(Error::Io(e)))?;
|
||||
let split = split_params(content);
|
||||
let mut parser = Parser::new(&split.md, &self.templates);
|
||||
match parser.render() {
|
||||
Ok(body) => {
|
||||
let template = self.jinja_env.get_template(&page.template).or_else(|e| Err(Error::Jinja(e)))?;
|
||||
let html = template.render(context! {
|
||||
index => index.to_minijinja(),
|
||||
index => self.site.to_minijinja(),
|
||||
is_error_not_found => false,
|
||||
url => page.get_url(),
|
||||
body => md,
|
||||
body,
|
||||
params => Renderer::convert_yaml(split.yaml)
|
||||
}).unwrap();
|
||||
}).or_else(|e| Err(Error::Jinja(e)))?;
|
||||
|
||||
Some(html)
|
||||
Ok(html)
|
||||
},
|
||||
None => None
|
||||
}
|
||||
},
|
||||
Err(_) => None,
|
||||
Err(e) => Err(Error::Parser(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,36 @@
|
||||
|
||||
pub mod indexer {
|
||||
use std::{collections::BTreeMap, ffi::OsString, fs, path::Path};
|
||||
use core::fmt;
|
||||
use std::{collections::BTreeMap, ffi::OsString, fs, path::Path, io::Error as IoError};
|
||||
use hashlink::LinkedHashMap;
|
||||
use minijinja::{Environment, Error as JinjaError};
|
||||
use regex::Regex;
|
||||
use yaml_rust2::{Yaml, YamlLoader};
|
||||
|
||||
pub enum Error {
|
||||
ReadDir(IoError),
|
||||
ReadMd(IoError),
|
||||
UtfError(OsString),
|
||||
InvalidPathComponent,
|
||||
}
|
||||
impl fmt::Debug for Error {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::ReadDir(arg0) => f.debug_tuple("ReadDir").field(arg0).finish(),
|
||||
Self::ReadMd(arg0) => f.debug_tuple("ReadMd").field(arg0).finish(),
|
||||
Self::UtfError(arg0) => {
|
||||
let hex_code: Vec<String> = arg0.clone().into_encoded_bytes().iter().map(|byte| {
|
||||
let nibels = [((byte&0xF)+0x30), (((byte>>4)&0xF)+0x30)];
|
||||
str::from_utf8(&nibels).unwrap().to_owned()
|
||||
}).collect();
|
||||
write!(f, "UtfError 0x{}", hex_code.join(""))
|
||||
// f.debug_tuple("UtfError").field(arg0).finish()
|
||||
},
|
||||
Self::InvalidPathComponent => write!(f, "InvalidPathComponent"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct IndexItem {
|
||||
// path to source file. If none, it is a directory without an index page
|
||||
@@ -41,37 +67,36 @@ pub mod indexer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn index(path: &Path) -> Option<IndexItem> {
|
||||
pub fn index(path: &Path) -> Result<Option<IndexItem>, Error> {
|
||||
IndexItem::scan_entry(path, String::from("/"))
|
||||
}
|
||||
|
||||
fn scan_entry(path: &Path, last_url: String) -> Option<IndexItem> {
|
||||
fn scan_entry(path: &Path, last_url: String) -> Result<Option<IndexItem>, Error> {
|
||||
let mut item = IndexItem::new();
|
||||
if let Some(file_name) = path.file_name() {
|
||||
if let Some(file_name) = file_name.to_str() {
|
||||
let file_name = String::from(file_name);
|
||||
let file_name = path.file_name().ok_or(Error::InvalidPathComponent)?;
|
||||
let file_name = file_name.to_str().ok_or(Error::UtfError(file_name.to_owned()))?;
|
||||
if path.is_dir() {
|
||||
if file_name != "templates" {
|
||||
item.friendly = file_name.clone();
|
||||
item.friendly = file_name.to_string();
|
||||
item.path = last_url.clone();
|
||||
let url = if last_url == String::from("/") {
|
||||
format!("/{file_name}")
|
||||
let url = if last_url.ends_with("/") {
|
||||
format!("{last_url}{file_name}")
|
||||
} else {
|
||||
format!("{}/{file_name}", last_url.clone())
|
||||
format!("{last_url}/{file_name}")
|
||||
};
|
||||
let index_path = path.join("index.md");
|
||||
match IndexItem::scan_entry(&index_path, last_url.clone()) {
|
||||
Some(mut item) => {
|
||||
let sub_pages = IndexItem::scan_dir(&path, last_url);
|
||||
item.sub_pages = sub_pages.0;
|
||||
item.public = sub_pages.1;
|
||||
return Some(item);
|
||||
match IndexItem::scan_entry(&index_path, last_url.clone())? {
|
||||
Some(mut index_item) => {
|
||||
let sub_pages = IndexItem::scan_dir(&path, last_url)?;
|
||||
index_item.sub_pages = sub_pages.0;
|
||||
index_item.public = sub_pages.1;
|
||||
return Ok(Some(index_item));
|
||||
},
|
||||
None => {
|
||||
let sub_pages = IndexItem::scan_dir(&path, url);
|
||||
let sub_pages = IndexItem::scan_dir(&path, url)?;
|
||||
item.sub_pages = sub_pages.0;
|
||||
item.public = sub_pages.1;
|
||||
return Some(item);
|
||||
return Ok(Some(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,53 +107,39 @@ pub mod indexer {
|
||||
None => None,
|
||||
};
|
||||
if item.src == None || file_name.len() < 4 {
|
||||
return None;
|
||||
return Ok(None);
|
||||
}
|
||||
if file_name.ends_with(".md") {
|
||||
item.friendly = file_name.to_string().drain(..file_name.len()-3).collect();
|
||||
if item.friendly == "index" {
|
||||
item.friendly = String::from("");
|
||||
}
|
||||
let extention: String = file_name.clone().drain(file_name.len()-3..).collect();
|
||||
if extention == ".md" {
|
||||
let friendly = file_name.clone().drain(..file_name.len()-3).collect();
|
||||
item.friendly = if friendly == "index" {
|
||||
String::from("")
|
||||
} else {
|
||||
friendly
|
||||
};
|
||||
item.path = last_url;
|
||||
let md = fs::read_to_string(path);
|
||||
match md {
|
||||
Ok(md) => {
|
||||
let md = fs::read_to_string(path).or_else(|e| Err(Error::ReadMd(e)))?;
|
||||
let params = split_params(md).yaml;
|
||||
IndexItem::parse_params(&mut item, params);
|
||||
return Some(item)
|
||||
},
|
||||
Err(_) => todo!()
|
||||
}
|
||||
return Ok(Some(item))
|
||||
}
|
||||
else {
|
||||
item.is_asset = true;
|
||||
item.friendly = file_name.clone();
|
||||
item.friendly = file_name.to_string();
|
||||
item.path = last_url;
|
||||
return Some(item);
|
||||
}
|
||||
}
|
||||
return None
|
||||
return Ok(Some(item));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn scan_dir(path: &Path, last_url: String) -> (Vec<Box<IndexItem>>, bool) {
|
||||
fn scan_dir(path: &Path, last_url: String) -> Result<(Vec<Box<IndexItem>>, bool), Error> {
|
||||
let mut items: Vec<Box<IndexItem>> = Vec::new();
|
||||
let mut has_public: bool = false;
|
||||
|
||||
let list = fs::read_dir(path);
|
||||
match list {
|
||||
Ok(list) => {
|
||||
let list = fs::read_dir(path).or_else(|e| Err(Error::ReadDir(e)))?;
|
||||
for entry in list {
|
||||
match entry {
|
||||
Ok(entry) => {
|
||||
let entry = entry.or_else(|e| Err(Error::ReadDir(e)))?;
|
||||
if entry.file_name() != OsString::from("index.md") {
|
||||
let item = IndexItem::scan_entry(&entry.path(), last_url.clone());
|
||||
let item = IndexItem::scan_entry(&entry.path(), last_url.clone())?;
|
||||
if let Some(i) = item {
|
||||
if i.public {
|
||||
has_public = true;
|
||||
@@ -136,16 +147,10 @@ pub mod indexer {
|
||||
items.push(Box::from(i));
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(_) => todo!()
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(_) => todo!()
|
||||
};
|
||||
|
||||
items.sort_by(|i, c| i.friendly.cmp(&c.friendly));
|
||||
(items, has_public)
|
||||
Ok((items, has_public))
|
||||
}
|
||||
|
||||
fn parse_params(item: &mut IndexItem, params: Yaml) {
|
||||
@@ -214,10 +219,10 @@ pub mod indexer {
|
||||
pub extention: String,
|
||||
pub path: Option<String>,
|
||||
pub src: Option<String>,
|
||||
pub sub_templates: Vec<Box<Template>>
|
||||
pub sub_templates: Vec<Template>
|
||||
}
|
||||
impl Template {
|
||||
fn new() -> Template {
|
||||
const fn new() -> Template {
|
||||
Template {
|
||||
name: String::new(),
|
||||
extention: String::new(),
|
||||
@@ -254,31 +259,28 @@ pub mod indexer {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn index(path: &Path) -> Vec<Box<Self>> {
|
||||
match Self::scan_template(path) {
|
||||
Some(templates) => templates.sub_templates,
|
||||
None => Vec::new(),
|
||||
pub fn index(path: &Path) -> Result<Vec<Self>, Error> {
|
||||
match Self::scan_template(path)? {
|
||||
Some(templates) => Ok(templates.sub_templates),
|
||||
None => Ok(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
fn scan_template(path: &Path) -> Option<Self> {
|
||||
fn scan_template(path: &Path) -> Result<Option<Self>, Error> {
|
||||
let mut item = Template::new();
|
||||
if let Some(file_name) = path.file_name() {
|
||||
if let Some(file_name) = file_name.to_str() {
|
||||
let file_name = String::from(file_name);
|
||||
if path.is_dir() {
|
||||
item.name = file_name;
|
||||
item.sub_templates = Template::scan_dir(&path);
|
||||
return Some(item);
|
||||
item.sub_templates = Template::scan_dir(&path)?;
|
||||
return Ok(Some(item));
|
||||
}
|
||||
else if path.is_file() {
|
||||
item.path = match path.to_str() {
|
||||
Some(path) => Some(String::from(path)),
|
||||
None => None,
|
||||
None => return Ok(None),
|
||||
};
|
||||
if item.path == None {
|
||||
return None;
|
||||
}
|
||||
|
||||
let path = item.path.clone().unwrap();
|
||||
item.src = match fs::read_to_string(path) {
|
||||
@@ -292,43 +294,52 @@ pub mod indexer {
|
||||
let dot = dot.get(0).unwrap();
|
||||
item.extention = file_name.clone().drain(dot.end()..).collect();
|
||||
item.name = file_name.clone().drain(..dot.start()).collect();
|
||||
return Some(item);
|
||||
return Ok(Some(item));
|
||||
}
|
||||
else {
|
||||
item.name = file_name;
|
||||
return Some(item);
|
||||
return Ok(Some(item));
|
||||
}
|
||||
}
|
||||
return None
|
||||
return Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn scan_dir(path: &Path) -> Vec<Box<Template>> {
|
||||
let mut items: Vec<Box<Template>> = Vec::new();
|
||||
fn scan_dir(path: &Path) -> Result<Vec<Template>, Error> {
|
||||
let mut items: Vec<Template> = Vec::new();
|
||||
|
||||
let list = fs::read_dir(path);
|
||||
match list {
|
||||
Ok(list) => {
|
||||
let list = fs::read_dir(path).or(Err(Error::InvalidPathComponent))?;
|
||||
for entry in list {
|
||||
match entry {
|
||||
Ok(entry) => {
|
||||
let item = Template::scan_template(&entry.path());
|
||||
let entry = entry.or_else(|e| Err(Error::ReadDir(e)))?;
|
||||
let item: Option<Template> = Template::scan_template(&entry.path())?;
|
||||
if let Some(i) = item {
|
||||
items.push(Box::from(i));
|
||||
}
|
||||
},
|
||||
Err(_) => todo!()
|
||||
items.push(i);
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(_) => todo!()
|
||||
};
|
||||
|
||||
items.sort_by(|i, c| i.name.cmp(&c.name));
|
||||
items
|
||||
Ok(items)
|
||||
}
|
||||
}
|
||||
impl Template {
|
||||
pub fn add_to_jinja_env(&self, env: &mut Environment) -> Result<(), JinjaError> {
|
||||
self.add_to_jinja_env_with_path(env, String::new())
|
||||
}
|
||||
|
||||
fn add_to_jinja_env_with_path(&self, env: &mut Environment, mut path: String) -> Result<(), JinjaError> {
|
||||
path.push_str(&self.name);
|
||||
if let Some(source) = &self.src {
|
||||
env.add_template_owned(path.clone(), source.clone())?;
|
||||
}
|
||||
path.push_str("/");
|
||||
for tmpl in self.sub_templates.iter() {
|
||||
tmpl.add_to_jinja_env_with_path(env, path.clone())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,50 @@
|
||||
use std::{collections::BTreeMap};
|
||||
|
||||
use pulldown_cmark::{Event, Options, Parser, Tag};
|
||||
use minijinja::{context, Environment, Value};
|
||||
use pulldown_cmark::{Options, Parser as PulldownParser, Tree, TreeEvent};
|
||||
use minijinja::{Environment, Value, context, Error as JinjaError};
|
||||
use regex::Regex;
|
||||
|
||||
pub fn parse_md(md: String, jinja_env: &Environment) -> Option<String> {
|
||||
use crate::render::Template;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
NoCurrentEvent,
|
||||
JinjaError(JinjaError),
|
||||
TemplateNotFound(String)
|
||||
}
|
||||
impl PartialEq for Error {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(Self::JinjaError(l0), Self::JinjaError(r0)) => {
|
||||
l0.kind() == r0.kind()
|
||||
},
|
||||
_ => core::mem::discriminant(self) == core::mem::discriminant(other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Parser<'a> {
|
||||
md: &'a str,
|
||||
tree: Option<Tree<TreeEvent>>,
|
||||
templates: &'a Vec<Template>,
|
||||
jinja_env: Environment<'a>
|
||||
}
|
||||
impl<'a> Parser<'a> {
|
||||
pub fn new(md: &'a str, templates: &'a Vec<Template>) -> Self {
|
||||
let mut env = Environment::new();
|
||||
for tmpl in templates.iter() {
|
||||
tmpl.add_to_jinja_env(&mut env).unwrap();
|
||||
};
|
||||
|
||||
Self {
|
||||
md,
|
||||
tree: None,
|
||||
templates,
|
||||
jinja_env: env
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&mut self) -> Result<String, Error> {
|
||||
let mut options = Options::empty();
|
||||
options.insert(Options::ENABLE_TABLES);
|
||||
options.insert(Options::ENABLE_FOOTNOTES);
|
||||
@@ -22,112 +62,520 @@ pub fn parse_md(md: String, jinja_env: &Environment) -> Option<String> {
|
||||
options.insert(Options::ENABLE_SUBSCRIPT);
|
||||
options.insert(Options::ENABLE_WIKILINKS);
|
||||
|
||||
let md = md_preprocessor(&md, jinja_env);
|
||||
let md = self.md_preprocessor()?;
|
||||
let mut parser = PulldownParser::new_ext(&md, options);
|
||||
self.tree = Some(parser.to_event_tree());
|
||||
let mut branch = Vec::new();
|
||||
|
||||
// let mut parser = Parser::new_ext("", options);
|
||||
// let mut in_heading_two: Vec<Event> = Vec::new();
|
||||
let parser = Parser::new_ext(&md, options).filter_map(|event| {
|
||||
match &event {
|
||||
Event::Start(tag) => {
|
||||
match tag {
|
||||
Tag::Paragraph => Some(event),
|
||||
Tag::Heading { level, id, classes, attrs } => Some(event),
|
||||
Tag::BlockQuote(_block_quote_kind) => Some(event),
|
||||
Tag::CodeBlock(_code_block_kind) => Some(event),
|
||||
Tag::HtmlBlock => Some(event),
|
||||
Tag::List(_) => Some(event),
|
||||
Tag::Item => Some(event),
|
||||
Tag::FootnoteDefinition(_cow_str) => Some(event),
|
||||
Tag::DefinitionList => Some(event),
|
||||
Tag::DefinitionListTitle => Some(event),
|
||||
Tag::DefinitionListDefinition => Some(event),
|
||||
Tag::Table(_alignments) => Some(event),
|
||||
Tag::TableHead => Some(event),
|
||||
Tag::TableRow => Some(event),
|
||||
Tag::TableCell => Some(event),
|
||||
Tag::Emphasis => Some(event),
|
||||
Tag::Strong => Some(event),
|
||||
Tag::Strikethrough => Some(event),
|
||||
Tag::Superscript => Some(event),
|
||||
Tag::Subscript => Some(event),
|
||||
Tag::Link { link_type, dest_url, title, id } => {
|
||||
self.md_parser_children(&mut branch)
|
||||
}
|
||||
|
||||
fn md_preprocessor(&self) -> Result<String, Error> {
|
||||
let mut new = String::with_capacity(self.md.len());
|
||||
let mut last_match = 0;
|
||||
let re = Regex::new(r"\{\% ([^}]*)\(([^}]*)\) \%\}").unwrap();
|
||||
for caps in re.captures_iter(self.md) {
|
||||
let m = caps.get(0).unwrap();
|
||||
new.push_str(&self.md[last_match..m.start()]);
|
||||
let template = &caps[1];
|
||||
let args = &caps[2];
|
||||
new.push_str(&self.render_component(template, parse_args(args))?);
|
||||
last_match = m.end();
|
||||
}
|
||||
new.push_str(&self.md[last_match..]);
|
||||
Ok(new)
|
||||
}
|
||||
|
||||
fn md_parser_children(&mut self, branch: &mut Vec<TreeEvent>) -> Result<String, Error> {
|
||||
let mut content = String::new();
|
||||
loop {
|
||||
let event = self.tree.as_ref().unwrap().get_cur().unwrap();
|
||||
let child_content = match self.tree.as_mut().unwrap().goto_first_child() {
|
||||
Some(_) => {
|
||||
branch.push(event.clone());
|
||||
let content = self.md_parser_children(branch)?;
|
||||
branch.pop();
|
||||
self.tree.as_mut().unwrap().goto_parent();
|
||||
|
||||
content
|
||||
},
|
||||
None => String::new(),
|
||||
};
|
||||
content.push_str(&self.md_parser_event(branch, child_content)?);
|
||||
|
||||
if self.tree.as_mut().unwrap().goto_next() == None {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(content)
|
||||
}
|
||||
|
||||
fn md_parser_event(&self, branch: &Vec<TreeEvent>, content: String) -> Result<String, Error> {
|
||||
match self.tree.as_ref().unwrap().get_cur().ok_or(Error::NoCurrentEvent)? {
|
||||
TreeEvent::Root => {
|
||||
Ok(content)
|
||||
},
|
||||
TreeEvent::Paragraph => {
|
||||
self.render_component("Paragraph", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<p>{content}</p>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Heading { level, id, classes, attrs } => {
|
||||
self.render_component("Heading", context! {
|
||||
content,
|
||||
parents => branch,
|
||||
level => level as u8,
|
||||
id, classes, attrs
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<h{level}>{content}</h{level}>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::BlockQuote(block_quote_kind) => {
|
||||
self.render_component("BlockQuote", context! {
|
||||
content,
|
||||
parents => branch,
|
||||
block_quote_kind
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::CodeBlock => {
|
||||
self.render_component("CodeBlock", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<p><code>{content}</code></p>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::ContainerBlock(container_kind, _) => {
|
||||
self.render_component("ContainerBlock", context! {
|
||||
content,
|
||||
parents => branch,
|
||||
container_kind
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::HtmlBlock => {
|
||||
self.render_component("HtmlBlock", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(content)
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::List(_) => {
|
||||
self.render_component("List", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<ul>{content}</ul>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Item => {
|
||||
self.render_component("Item", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<li>{content}</li>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::FootnoteDefinition(_) => {
|
||||
self.render_component("FootnoteDefinition", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::DefinitionList => {
|
||||
self.render_component("DefinitionList", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::DefinitionListTitle => {
|
||||
self.render_component("DefinitionListTitle", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::DefinitionListDefinition => {
|
||||
self.render_component("DefinitionListDefinition", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Table(alignments) => {
|
||||
self.render_component("Table", context! {
|
||||
content,
|
||||
parents => branch,
|
||||
alignments
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::TableHead => {
|
||||
self.render_component("TableHead", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<th>{content}</th>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::TableRow => {
|
||||
self.render_component("TableRow", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<tr>{content}</tr>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::TableCell => {
|
||||
self.render_component("TableCell", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<td>{content}</td>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Emphasis => {
|
||||
self.render_component("Emphasis", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Strong => {
|
||||
self.render_component("Strong", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Strikethrough => {
|
||||
self.render_component("Strikethrough", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Superscript => {
|
||||
self.render_component("Superscript", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Subscript => {
|
||||
self.render_component("Subscript", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Link { link_type, dest_url, title, id } => {
|
||||
let re = Regex::new(r"^%(?<tags>[^%]+)%").unwrap();
|
||||
// let out = .unwrap();
|
||||
let (url, args) = match re.captures(&dest_url) {
|
||||
let (_, args) = match re.captures(&dest_url) {
|
||||
Some(args) => {
|
||||
(dest_url.strip_prefix(args.get(0).unwrap().as_str()).unwrap().to_string(), parse_args(args.name("tags").unwrap().as_str()))
|
||||
(
|
||||
dest_url.strip_prefix(args.get(0).unwrap().as_str()).unwrap().to_string(),
|
||||
parse_args(args.name("tags").unwrap().as_str())
|
||||
)
|
||||
},
|
||||
None => (dest_url.to_string(), Value::UNDEFINED)
|
||||
};
|
||||
match render_component("link_start", context! {
|
||||
link_type => link_type,
|
||||
dest_url => url,
|
||||
title => title,
|
||||
id => id,
|
||||
args => args
|
||||
}, jinja_env)
|
||||
{
|
||||
Some(html) => Some(Event::Html(html.into())),
|
||||
None => Some(event),
|
||||
self.render_component("Link", context! {
|
||||
content,
|
||||
parents => branch,
|
||||
link_type, dest_url, title, id, args
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<a href=\"{dest_url}\">{content}</a>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
Tag::Image { link_type, dest_url, title, id } => Some(event),
|
||||
Tag::MetadataBlock(_metadata_block_kind) => Some(event),
|
||||
TreeEvent::Image { link_type, dest_url, title, id } => {
|
||||
self.render_component("Image", context! {
|
||||
content,
|
||||
parents => branch,
|
||||
link_type, dest_url, title, id
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::MetadataBlock(metadata_block_kind) => {
|
||||
self.render_component("MetadataBlock", context! {
|
||||
content,
|
||||
parents => branch,
|
||||
metadata_block_kind
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Text(text) => {
|
||||
self.render_component("Text", context! {
|
||||
content,
|
||||
parents => branch,
|
||||
text
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("{content}"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Code(_) => {
|
||||
self.render_component("Code", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("<code>{content}</code>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::InlineMath(_) => {
|
||||
self.render_component("InlineMath", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::DisplayMath(_) => {
|
||||
self.render_component("DisplayMath", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Html(html) => {
|
||||
self.render_component("Html", context! {
|
||||
content => html,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(html)
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::InlineHtml(html) => {
|
||||
self.render_component("InlineHtml", context! {
|
||||
content => html,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(html)
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::FootnoteReference(_) => {
|
||||
self.render_component("FootnoteReference", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::SoftBreak => {
|
||||
self.render_component("SoftBreak", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!(" "))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::HardBreak => {
|
||||
self.render_component("HardBreak", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
Ok(format!("</br>"))
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::Rule => {
|
||||
self.render_component("Rule", context! {
|
||||
content,
|
||||
parents => branch
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
TreeEvent::TaskListMarker(checked) => {
|
||||
self.render_component("TaskListMarker", context! {
|
||||
content,
|
||||
parents => branch,
|
||||
checked
|
||||
}).or_else(|e| {
|
||||
if let Error::TemplateNotFound(_) = e {
|
||||
todo!()
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})
|
||||
},
|
||||
Event::End(_tag_end) => Some(event),
|
||||
Event::Text(_cow_str) => Some(event),
|
||||
Event::Code(_cow_str) => Some(event),
|
||||
Event::InlineMath(_cow_str) => Some(event),
|
||||
Event::DisplayMath(_cow_str) => Some(event),
|
||||
Event::Html(_cow_str) => Some(event),
|
||||
Event::InlineHtml(_cow_str) => Some(event),
|
||||
Event::FootnoteReference(_cow_str) => Some(event),
|
||||
Event::SoftBreak => Some(event),
|
||||
Event::HardBreak => Some(event),
|
||||
Event::Rule => Some(event),
|
||||
Event::TaskListMarker(_) => Some(event),
|
||||
}
|
||||
});
|
||||
let mut html = String::new();
|
||||
pulldown_cmark::html::push_html(&mut html, parser);
|
||||
|
||||
Some(html)
|
||||
}
|
||||
|
||||
fn md_preprocessor(md: &String, jinja_env: &Environment) -> String {
|
||||
let re = Regex::new(r"\{\% *(.*)\((.*)\).*\%\}").unwrap();
|
||||
let out = re.replace_all(md, |capture: ®ex::Captures<'_>| {
|
||||
let template = &capture[1];
|
||||
let args = &capture[2];
|
||||
match render_component(template, context! { args => parse_args(args)}, jinja_env){
|
||||
Some(html) => html,
|
||||
None => String::from("")
|
||||
}
|
||||
});
|
||||
|
||||
String::from(out)
|
||||
}
|
||||
|
||||
fn render_component(component: &str, args: Value, jinja_env: &Environment) -> Option<String> {
|
||||
// println!(" tag found: {component} <- {args}");
|
||||
match jinja_env.get_template(&format!("components/{component}")) {
|
||||
Ok(ding) => {
|
||||
// match ding.render(context! { args => args }) {
|
||||
match ding.render(args) {
|
||||
Ok(html) => Some(html),
|
||||
Err(err) => {
|
||||
println!("ERROR: faild to render template: {component} ({err:?})");
|
||||
None
|
||||
},
|
||||
fn render_component(&self, component: &str, args: Value) -> Result<String, Error> {
|
||||
match self.jinja_env.get_template(&format!("components/{component}")) {
|
||||
Ok(tmpl) => {
|
||||
match tmpl.render(args) {
|
||||
Ok(html) => Ok(html),
|
||||
Err(err) => Err(Error::JinjaError(err)),
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
println!("ERROR: could not find template: {component}");
|
||||
Some("".to_string())
|
||||
Err(e) => {
|
||||
match e.kind() {
|
||||
minijinja::ErrorKind::TemplateNotFound =>
|
||||
Err(Error::TemplateNotFound(format!("components/{component}"))),
|
||||
_ => Err(Error::JinjaError(e)),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const NUMBER: i8 = 0;
|
||||
const STRING: i8 = 1;
|
||||
|
||||
Reference in New Issue
Block a user