feat: bootstrap templates

This commit is contained in:
Aravinth Manivannan 2022-05-18 20:28:07 +05:30
parent 26a4d1f39f
commit 5877c39bef
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
11 changed files with 354 additions and 51 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@
**/target/
tmp
tarpaulin-report.html
src/cache_buster_data.json

240
Cargo.lock generated
View file

@ -2,30 +2,6 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "actix"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f728064aca1c318585bf4bb04ffcfac9e75e508ab4e8b1bd9ba5dfe04e2cbed5"
dependencies = [
"actix-rt",
"actix_derive",
"bitflags",
"bytes",
"crossbeam-channel",
"futures-core",
"futures-sink",
"futures-task",
"futures-util",
"log",
"once_cell",
"parking_lot 0.12.0",
"pin-project-lite",
"smallvec",
"tokio",
"tokio-util 0.7.1",
]
[[package]]
name = "actix-codec"
version = "0.5.0"
@ -221,17 +197,6 @@ dependencies = [
"syn",
]
[[package]]
name = "actix_derive"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d44b8fee1ced9671ba043476deddef739dd0959bf77030b26b738cc591737a7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "adler"
version = "1.0.2"
@ -389,6 +354,15 @@ dependencies = [
"generic-array 0.12.4",
]
[[package]]
name = "block-buffer"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
dependencies = [
"generic-array 0.14.5",
]
[[package]]
name = "block-buffer"
version = "0.10.2"
@ -470,6 +444,21 @@ dependencies = [
"bytes",
]
[[package]]
name = "cache-buster"
version = "0.2.0"
source = "git+https://github.com/realaravinth/cache-buster#7ca4545722fb99be30698a5e72c7d982a70fa11f"
dependencies = [
"data-encoding",
"derive_builder",
"mime",
"mime_guess",
"serde",
"serde_json",
"sha2 0.10.2",
"walkdir",
]
[[package]]
name = "cc"
version = "1.0.73"
@ -571,7 +560,7 @@ dependencies = [
"hmac",
"percent-encoding",
"rand",
"sha2",
"sha2 0.10.2",
"subtle",
"time 0.3.9",
"version_check",
@ -626,16 +615,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-queue"
version = "0.3.5"
@ -675,6 +654,41 @@ dependencies = [
"cipher",
]
[[package]]
name = "darling"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4529658bdda7fd6769b8614be250cdcfc3aeb0ee72fe66f9e41e5e5eb73eac02"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "649c91bc01e8b1eac09fb91e8dbc7d517684ca6be8ebc75bb9cafc894f9fdb6f"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddfc69c5bfcbd2fc09a0f38451d2daf0e372e367986a83906d1b0dbc88134fb5"
dependencies = [
"darling_core",
"quote",
"syn",
]
[[package]]
name = "data-encoding"
version = "2.3.2"
@ -703,6 +717,37 @@ dependencies = [
"url",
]
[[package]]
name = "derive_builder"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07adf7be193b71cc36b193d0f5fe60b918a3a9db4dad0449f57bcfd519704a3"
dependencies = [
"derive_builder_macro",
]
[[package]]
name = "derive_builder_core"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f91d4cfa921f1c05904dc3c57b4a32c38aed3340cce209f3a6fd1478babafc4"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "derive_builder_macro"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f0314b72bed045f3a68671b3c86328386762c93f82d98c65c3cb5e5f573dd68"
dependencies = [
"derive_builder_core",
"syn",
]
[[package]]
name = "derive_more"
version = "0.99.17"
@ -731,6 +776,15 @@ dependencies = [
"generic-array 0.12.4",
]
[[package]]
name = "digest"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
dependencies = [
"generic-array 0.14.5",
]
[[package]]
name = "digest"
version = "0.10.3"
@ -1269,6 +1323,12 @@ dependencies = [
"tokio-native-tls",
]
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "idna"
version = "0.2.3"
@ -1505,6 +1565,16 @@ version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "mime_guess"
version = "2.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
dependencies = [
"mime",
"unicase",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
@ -2148,6 +2218,40 @@ dependencies = [
"serde",
]
[[package]]
name = "rust-embed"
version = "6.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a17e5ac65b318f397182ae94e532da0ba56b88dd1200b774715d36c4943b1c3"
dependencies = [
"rust-embed-impl",
"rust-embed-utils",
"walkdir",
]
[[package]]
name = "rust-embed-impl"
version = "6.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94e763e24ba2bf0c72bc6be883f967f794a019fafd1b86ba1daff9c91a7edd30"
dependencies = [
"proc-macro2",
"quote",
"rust-embed-utils",
"syn",
"walkdir",
]
[[package]]
name = "rust-embed-utils"
version = "7.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "756feca3afcbb1487a1d01f4ecd94cf8ec98ea074c55a69e7136d29fb6166029"
dependencies = [
"sha2 0.9.9",
"walkdir",
]
[[package]]
name = "rust-ini"
version = "0.18.0"
@ -2419,6 +2523,19 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012"
[[package]]
name = "sha2"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
dependencies = [
"block-buffer 0.9.0",
"cfg-if",
"cpufeatures",
"digest 0.9.0",
"opaque-debug 0.3.0",
]
[[package]]
name = "sha2"
version = "0.10.2"
@ -2554,7 +2671,7 @@ dependencies = [
"serde",
"serde_json",
"sha-1 0.10.0",
"sha2",
"sha2 0.10.2",
"smallvec",
"sqlformat",
"sqlx-rt",
@ -2584,7 +2701,7 @@ dependencies = [
"quote",
"serde",
"serde_json",
"sha2",
"sha2 0.10.2",
"sqlx-core",
"sqlx-rt",
"syn",
@ -2616,11 +2733,11 @@ dependencies = [
name = "starchart"
version = "0.1.0"
dependencies = [
"actix",
"actix-identity",
"actix-rt",
"actix-web",
"async-trait",
"cache-buster",
"config",
"db-core",
"db-sqlx-sqlite",
@ -2630,11 +2747,14 @@ dependencies = [
"gitea",
"lazy_static",
"log",
"mime",
"mime_guess",
"mktemp",
"pretty_env_logger",
"publiccodeyml",
"rand",
"reqwest",
"rust-embed",
"serde",
"serde_json",
"sqlx",
@ -2642,6 +2762,7 @@ dependencies = [
"tokio",
"trust-dns-resolver",
"url",
"urlencoding",
"validator",
]
@ -2704,6 +2825,12 @@ dependencies = [
"unicode-normalization",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "subtle"
version = "2.4.1"
@ -3133,6 +3260,15 @@ dependencies = [
"unic-common",
]
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check",
]
[[package]]
name = "unicode-bidi"
version = "0.3.8"
@ -3195,6 +3331,12 @@ dependencies = [
"serde",
]
[[package]]
name = "urlencoding"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68b90931029ab9b034b300b797048cf23723400aa757e8a2bfb9d748102f9821"
[[package]]
name = "uuid"
version = "0.8.2"

View file

@ -10,7 +10,7 @@ license = "AGPLv3 or later version"
build = "build.rs"
[workspace]
exclude = ["db/migrator"]
exclude = ["db/migrator", "utils/cache-bust"]
members = [
".",
"db/db-core",
@ -24,11 +24,12 @@ members = [
[dependencies]
actix-rt = "2.7"
actix-web = "4.0.1"
actix = "0.13"
actix-identity = "0.4.0"
async-trait = "0.1.51"
config = "0.13.0"
lazy_static = "1.4.0"
mime = "0.3.16"
mime_guess = "2.0.3"
rand = "0.8.5"
tera = "1.15"
tokio = { version = "1.17", features = ["fs", "time"] }
@ -37,6 +38,11 @@ validator = { version = "0.15", features = ["derive"]}
derive_more = "0.99.17"
log = "0.4.16"
pretty_env_logger = "0.4"
rust-embed = "6.3.0"
urlencoding = "2.1.0"
[dependencies.cache-buster]
git = "https://github.com/realaravinth/cache-buster"
[dependencies.reqwest]
features = ["rustls-tls-native-roots", "gzip", "deflate", "brotli", "json"]

View file

@ -25,6 +25,10 @@ define test_federation
cargo test --no-fail-fast
endef
define cache_bust ## run cache_busting program
cd utils/cache-bust && cargo run
endef
define test_workspaces
$(call test_databases)
$(call test_forges)
@ -33,8 +37,12 @@ define test_workspaces
endef
default: ## Debug build
$(call cache_bust)
cargo build
cache-bust: ## Run cache buster on static assets
$(call cache_bust)
clean: ## Clean all build artifacts and dependencies
@-/bin/rm -rf target/
@-/bin/rm -rf database/migrator/target/
@ -43,6 +51,8 @@ clean: ## Clean all build artifacts and dependencies
@cargo clean
coverage: migrate ## Generate coverage report in HTML format
$(call launch_test_env)
$(call cache_bust)
cargo tarpaulin -t 1200 --out Html --skip-clean --all-features --no-fail-fast --workspace=db/db-sqlx-sqlite,forge/gitea,federate/publiccodeyml,.
check: ## Check for syntax errors on all workspaces
@ -56,6 +66,7 @@ check: ## Check for syntax errors on all workspaces
cd forge/gitea && cargo check --tests --all-features
cd federate/federate-core && cargo check --tests --all-features
cd federate/publiccodeyml && cargo check --tests --all-features
cd utils/cache-bust && cargo check --tests --all-features
dev-env: ## Download development dependencies
$(call launch_test_env)
@ -76,6 +87,7 @@ lint: ## Lint codebase
cargo clippy --workspace --tests --all-features
release: ## Release build
$(call cache_bust)
cargo build --release
run: default ## Run debug build
@ -93,6 +105,7 @@ sqlx-offline-data: ## prepare sqlx offline data
--all-features
test: migrate ## Run tests
$(call launch_test_env)
$(call cache_bust)
$(call test_workspaces)
# cd database/db-sqlx-postgres &&\
@ -100,6 +113,8 @@ test: migrate ## Run tests
# cargo test --no-fail-fast
xml-test-coverage: migrate ## Generate cobertura.xml test coverage
$(call launch_test_env)
$(call cache_bust)
cargo tarpaulin -t 1200 --out XMl --skip-clean --all-features --no-fail-fast --workspace=db/db-sqlx-sqlite,forge/gitea,federate/publiccodeyml,.
help: ## Prints help for targets with comments

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="{{ assets.css }}" />
<title>Gists</title>
<title>{% block title %} {% endblock %}</title>
</head>
<body>
<header>{% block nav %} {% endblock %}</header>
<main>{% block main %} {% endblock %}</main>
{% include "footer" %}
</body>
</html>

View file

@ -0,0 +1,6 @@
{% if error %}
<div class="error_container">
<h3 class="error-title">ERROR: {{ error.title }}</h3>
<p class="error-message">{{ error.reason }}</p>
</div>
{% endif %}

View file

@ -0,0 +1,46 @@
<footer>
<div class="footer__container">
<div class="footer__column">
<span class="license__conatiner">
<a class="license__link" rel="noreferrer" href="/docs" target="_blank"
>Docs</a
>
<span class="footer__column-divider--mobile-visible">|</span>
<a
class="license__link"
rel="noreferrer"
href="https://www.eff.org/issues/do-not-track/amp/"
target="_blank"
>No AMP</a
>
</span>
</div>
<div class="footer__column">
<a
href="/"
class="footer__link"
target="_blank"
rel="noopener"
title="RSS"
>
Home
</a>
<div class="footer__column-divider">|</div>
<a href="mailto:{{ footer.admin_email }}" class="footer__link"
>Contact Instance Maintainer</a
>
<div class="footer__column-divider">|</div>
<a
class="footer__link"
href="{{ footer.source_code }}"
target="_blank"
rel="noopener"
title="Source Code"
>
v{{ footer.version }}-{{ footer.git_hash }}
</a>
</div>
</div>
</footer>

View file

@ -0,0 +1,28 @@
<nav class="nav__container">
<input type="checkbox" class="nav__toggle" id="nav__toggle" />
<div class="nav__header">
<a class="nav__logo-container" href="/">
<p class="nav__home-btn">GitPad</p>
</a>
<label class="nav__hamburger-menu" for="nav__toggle">
<span class="nav__hamburger-inner"></span>
</label>
</div>
<div class="nav__spacer"></div>
<div class="nav__link-group">
<div class="nav__link-container">
<a class="nav__link" rel="noreferrer" href="{{ page.gist.new }}">New Paste</a>
</div>
{% if loggedin_user %}
<div class="nav__link-container">
<a class="nav__link" rel="noreferrer" href="{{ loggedin_user }}">Profile</a>
</div>
{% endif %}
<div class="nav__link-container">
<a class="nav__link" rel="noreferrer" href="{{ page.auth.logout }}">Log out</a>
</div>
</div>
</nav>

View file

@ -0,0 +1,18 @@
<nav class="nav__container">
<input type="checkbox" class="nav__toggle" id="nav__toggle" />
<div class="nav__header">
<a class="nav__logo-container" href="/">
<p class="nav__home-btn">GitPad</p>
</a>
<label class="nav__hamburger-menu" for="nav__toggle">
<span class="nav__hamburger-inner"></span>
</label>
</div>
<div class="nav__spacer"></div>
<div class="nav__link-group">
{% block nav_links %} {% endblock %}
</div>
</nav>

View file

@ -0,0 +1,26 @@
<nav class="nav__container">
<input type="checkbox" class="nav__toggle" id="nav__toggle" />
<div class="nav__header">
<a class="nav__logo-container" href="/">
<p class="nav__home-btn">GitPad</p>
</a>
<label class="nav__hamburger-menu" for="nav__toggle">
<span class="nav__hamburger-inner"></span>
</label>
</div>
<div class="nav__spacer"></div>
<div class="nav__link-group">
<div class="nav__link-container">
<a class="nav__link" rel="noreferrer" href="/explore">Explore</a>
</div>
<div class="nav__link-container">
<a class="nav__link" rel="noreferrer" href="{{ page.auth.login }}">Login</a>
</div>
<div class="nav__link-container">
<a class="nav__link" rel="noreferrer" href="{{ page.auth.register }}">Register</a>
</div>
</div>
</nav>

0
templates/index.html Normal file
View file