finally fix url!

also please a bit clippy
This commit is contained in:
Trinity Pointard 2019-07-23 00:07:23 +02:00 committed by Igor Galić
parent c5f6b88b1d
commit b172a80e35
No known key found for this signature in database
GPG Key ID: ACFEFF7F6A123A86
4 changed files with 19 additions and 6 deletions

View File

@ -1,7 +1,10 @@
use plume_models::{notifications::*, users::User, Connection, PlumeRocket}; use plume_models::{notifications::*, users::User, Connection, PlumeRocket};
use rocket::http::hyper::header::{ETag, EntityTag}; use rocket::http::hyper::header::{ETag, EntityTag};
use rocket::http::{Method, Status}; use rocket::http::{
uri::{FromUriParam, Query},
Method, Status,
};
use rocket::request::Request; use rocket::request::Request;
use rocket::response::{self, content::Html as HtmlCt, Responder, Response}; use rocket::response::{self, content::Html as HtmlCt, Responder, Response};
use rocket_i18n::Catalog; use rocket_i18n::Catalog;
@ -13,6 +16,16 @@ pub use askama_escape::escape;
pub static CACHE_NAME: &str = env!("CACHE_ID"); pub static CACHE_NAME: &str = env!("CACHE_ID");
pub struct NoValue; // workarround for missing FromUriParam implementation for Option
impl FromUriParam<Query, NoValue> for Option<i32> {
type Target = Option<i32>;
fn from_uri_param(_: NoValue) -> Self::Target {
None
}
}
pub type BaseContext<'a> = &'a ( pub type BaseContext<'a> = &'a (
&'a Connection, &'a Connection,
&'a Catalog, &'a Catalog,
@ -363,7 +376,7 @@ macro_rules! url {
common=[$($common_args:tt = $common_val:expr),*], common=[$($common_args:tt = $common_val:expr),*],
normal=[$($normal_args:tt = $normal_val:expr),*], normal=[$($normal_args:tt = $normal_val:expr),*],
custom=[$($custom_args:tt = $custom_val:expr),*]) => {{ custom=[$($custom_args:tt = $custom_val:expr),*]) => {{
let domain: Option<&plume_models::blogs::Host> = $domain.as_ref(); //for type inference with None let domain: &Option<plume_models::blogs::Host> = &$domain; //for type inference with None
$( $(
let $common_args = $common_val; let $common_args = $common_val;
)* )*
@ -372,7 +385,7 @@ macro_rules! url {
let $custom_args = $custom_val; let $custom_args = $custom_val;
)* )*
let origin = uri!(crate::routes::$module::custom::$route: let origin = uri!(crate::routes::$module::custom::$route:
$custom_domain = domain.as_ref(), $custom_domain = domain.to_string(),
$($common_args = $common_args,)* $($common_args = $common_args,)*
$($custom_args = $custom_args,)* $($custom_args = $custom_args,)*
); );

View File

@ -24,7 +24,7 @@
<link href='@Instance::get_local().unwrap().compute_box("~", &blog.fqn, "atom.xml")' rel='alternate' type='application/atom+xml'> <link href='@Instance::get_local().unwrap().compute_box("~", &blog.fqn, "atom.xml")' rel='alternate' type='application/atom+xml'>
<link href='@blog.ap_url' rel='alternate' type='application/activity+json'> <link href='@blog.ap_url' rel='alternate' type='application/activity+json'>
}, { }, {
<a href="@url!(custom_domain = *&blog.custom_domain, blogs::details: common=[page = None], normal=[name = &blog.fqn])" dir="auto">@blog.title</a> <a href="@url!(custom_domain = blog.custom_domain, blogs::details: common=[page = None], normal=[name = &blog.fqn])" dir="auto">@blog.title</a>
}, { }, {
<div class="hidden"> <div class="hidden">
@for author in authors { @for author in authors {

View File

@ -9,7 +9,7 @@
<div class="cover" style="background-image: url('@Html(article.cover_url(ctx.0).unwrap_or_default())')"></div> <div class="cover" style="background-image: url('@Html(article.cover_url(ctx.0).unwrap_or_default())')"></div>
} }
<h3 class="p-name" dir="auto"> <h3 class="p-name" dir="auto">
<a class="u-url" href="@url!(custom_domain = article.get_blog(ctx.0).unwrap().custom_domain, posts::details: common=[ slug = &article.slug, responding_to = None], normal=[blog = article.get_blog(ctx.0).unwrap().fqn])"> <a class="u-url" href="@url!(custom_domain = article.get_blog(ctx.0).unwrap().custom_domain, posts::details: common=[ slug = &article.slug, responding_to = NoValue], normal=[blog = article.get_blog(ctx.0).unwrap().fqn])">
@article.title @article.title
</a> </a>
</h3> </h3>

View File

@ -17,7 +17,7 @@
@if article.cover_id.is_some() { @if article.cover_id.is_some() {
<meta property="og:image" content="@Html(article.cover_url(ctx.0).unwrap_or_default())"/> <meta property="og:image" content="@Html(article.cover_url(ctx.0).unwrap_or_default())"/>
} }
<meta property="og:url" content="@url!(custom_domain = *&blog.custom_domain, posts::details: common=[slug = &article.slug, responding_to = None], normal=[blog = &blog.fqn])"/> <meta property="og:url" content="@url!(custom_domain = blog.custom_domain, posts::details: common=[slug = &article.slug, responding_to = NoValue], normal=[blog = &blog.fqn])"/>
<meta property="og:description" content="@article.subtitle"/> <meta property="og:description" content="@article.subtitle"/>
}, { }, {
<a href="@url!(custom_domain = &blog.custom_domain, blogs::details: common=[page = None], normal=[name = &blog.fqn])">@blog.title</a> <a href="@url!(custom_domain = &blog.custom_domain, blogs::details: common=[page = None], normal=[name = &blog.fqn])">@blog.title</a>