add go vanity import redirecting
This commit is contained in:
parent
3f4455d43a
commit
4a2daf542f
|
@ -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",
|
||||
|
|
|
@ -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"
|
||||
]
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "go_vanity"
|
||||
version = "0.1.0"
|
||||
authors = ["Christine Dodrill <me@christine.website>"]
|
||||
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"] }
|
|
@ -0,0 +1,5 @@
|
|||
use ructe::{Result, Ructe};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
Ructe::from_env()?.compile_templates("templates")
|
||||
}
|
|
@ -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<impl Reply, Rejection> {
|
||||
Response::builder().html(|o| templates::gitea_html(o, pkg_name, git_repo))
|
||||
}
|
||||
|
||||
pub async fn github(pkg_name: &str, git_repo: &str) -> Result<impl Reply, Rejection> {
|
||||
Response::builder().html(|o| templates::github_html(o, pkg_name, git_repo))
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
@(pkg_name: &str, git_repo: &str)
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<meta name="go-import" content="@pkg_name git @git_repo">
|
||||
<meta name="go-source" content="@pkg_name @git_repo @git_repo/src/master@{/dir@} @git_repo/src/master@{/dir@}/@{file@}#L@{line@}">
|
||||
<meta http-equiv="refresh" content="0; url=https://godoc.org/@pkg_name">
|
||||
</head>
|
||||
<body>
|
||||
Please see <a href="https://godoc.org/@pkg_name">here</a> for documentation on this package.
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,14 @@
|
|||
@(pkg_name: &str, git_repo: &str)
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<meta name="go-import" content="@pkg_name git @git_repo">
|
||||
<meta name="go-source" content="@pkg_name @git_repo @git_repo/tree/master@{/dir@} @git_repo/blob/master@{/dir@}/@{file@}#L@{line@}">
|
||||
<meta http-equiv="refresh" content="0; url=https://godoc.org/@pkg_name">
|
||||
</head>
|
||||
<body>
|
||||
Please see <a href="https://godoc.org/@pkg_name">here</a> for documentation on this package.
|
||||
</body>
|
||||
</html>
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue