diff --git a/Cargo.lock b/Cargo.lock index 983df14..914e17d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -668,6 +668,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "go_vanity" +version = "0.1.0" +dependencies = [ + "mime 0.3.16", + "ructe", + "warp", +] + [[package]] name = "h2" version = "0.2.6" @@ -2501,6 +2510,7 @@ dependencies = [ "comrak", "envy", "glob", + "go_vanity", "hyper", "jsonfeed", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index f389472..4d3089e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ warp = "0.2" xml-rs = "0.8" # workspace dependencies +go_vanity = { path = "./lib/go_vanity" } jsonfeed = { path = "./lib/jsonfeed" } [build-dependencies] @@ -39,5 +40,6 @@ ructe = { version = "0.11", features = ["warp02"] } [workspace] members = [ + "./lib/go_vanity", "./lib/jsonfeed" ] diff --git a/lib/go_vanity/Cargo.toml b/lib/go_vanity/Cargo.toml new file mode 100644 index 0000000..ae10f24 --- /dev/null +++ b/lib/go_vanity/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "go_vanity" +version = "0.1.0" +authors = ["Christine Dodrill "] +edition = "2018" +build = "src/build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +mime = "0.3.0" +warp = "0.2" + +[build-dependencies] +ructe = { version = "0.11", features = ["warp02"] } diff --git a/lib/go_vanity/src/build.rs b/lib/go_vanity/src/build.rs new file mode 100644 index 0000000..f36737c --- /dev/null +++ b/lib/go_vanity/src/build.rs @@ -0,0 +1,5 @@ +use ructe::{Result, Ructe}; + +fn main() -> Result<()> { + Ructe::from_env()?.compile_templates("templates") +} diff --git a/lib/go_vanity/src/lib.rs b/lib/go_vanity/src/lib.rs new file mode 100644 index 0000000..e4a11e2 --- /dev/null +++ b/lib/go_vanity/src/lib.rs @@ -0,0 +1,12 @@ +use warp::{http::Response, Rejection, Reply}; +use crate::templates::{RenderRucte}; + +include!(concat!(env!("OUT_DIR"), "/templates.rs")); + +pub async fn gitea(pkg_name: &str, git_repo: &str) -> Result { + Response::builder().html(|o| templates::gitea_html(o, pkg_name, git_repo)) +} + +pub async fn github(pkg_name: &str, git_repo: &str) -> Result { + Response::builder().html(|o| templates::github_html(o, pkg_name, git_repo)) +} diff --git a/lib/go_vanity/templates/gitea.rs.html b/lib/go_vanity/templates/gitea.rs.html new file mode 100644 index 0000000..b20985b --- /dev/null +++ b/lib/go_vanity/templates/gitea.rs.html @@ -0,0 +1,14 @@ +@(pkg_name: &str, git_repo: &str) + + + + + + + + + + + Please see here for documentation on this package. + + diff --git a/lib/go_vanity/templates/github.rs.html b/lib/go_vanity/templates/github.rs.html new file mode 100644 index 0000000..61f42e5 --- /dev/null +++ b/lib/go_vanity/templates/github.rs.html @@ -0,0 +1,14 @@ +@(pkg_name: &str, git_repo: &str) + + + + + + + + + + + Please see here for documentation on this package. + + diff --git a/src/main.rs b/src/main.rs index f961009..d14c691 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,6 +104,11 @@ async fn main() -> Result<()> { .and(with_state(state.clone())) .and_then(handlers::feeds::rss); + let go_vanity_jsonfeed = warp::path("jsonfeed") + .and(warp::any().map(move || "christine.website/jsonfeed")) + .and(warp::any().map(move || "https://tulpa.dev/Xe/jsonfeed")) + .and_then(go_vanity::gitea); + let metrics_endpoint = warp::path("metrics").and(warp::path::end()).map(move || { let encoder = TextEncoder::new(); let metric_families = prometheus::gather(); @@ -123,7 +128,7 @@ async fn main() -> Result<()> { .or(talk_index.or(talk_post_view)) .or(jsonfeed.or(atom).or(rss)) .or(files.or(css).or(favicon).or(sw.or(robots))) - .or(healthcheck.or(metrics_endpoint)) + .or(healthcheck.or(metrics_endpoint).or(go_vanity_jsonfeed)) .map(|reply| { warp::reply::with_header( reply,