aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2023-08-21 21:19:49 -0400
committerXe Iaso <me@xeiaso.net>2023-08-21 21:19:49 -0400
commit275327041b4ce5cac6e1adabc813ece54c646cd6 (patch)
treeab4f9ce5b8aff7e39ed9b11f229ecd166155fd85 /src
parent90da0c1daea6dfefe801548443a3889b19def2b2 (diff)
downloadxesite-275327041b4ce5cac6e1adabc813ece54c646cd6.tar.xz
xesite-275327041b4ce5cac6e1adabc813ece54c646cd6.zip
fix clippy suggestions
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'src')
-rw-r--r--src/app/config.rs9
-rw-r--r--src/handlers/blog.rs20
-rw-r--r--src/handlers/feeds.rs6
-rw-r--r--src/handlers/mod.rs2
-rw-r--r--src/handlers/streams.rs1
-rw-r--r--src/main.rs2
-rw-r--r--src/post/mod.rs15
-rw-r--r--src/tmpl/blog.rs4
-rw-r--r--src/tmpl/mod.rs6
9 files changed, 29 insertions, 36 deletions
diff --git a/src/app/config.rs b/src/app/config.rs
index e1a9b53..a0f1273 100644
--- a/src/app/config.rs
+++ b/src/app/config.rs
@@ -152,18 +152,13 @@ impl Render for Link {
}
}
-#[derive(Clone, Deserialize, Serialize)]
+#[derive(Clone, Default, Deserialize, Serialize)]
pub enum StockKind {
Grant,
+ #[default]
Options,
}
-impl Default for StockKind {
- fn default() -> Self {
- StockKind::Options
- }
-}
-
fn schema_context() -> String {
"http://schema.org/".to_string()
}
diff --git a/src/handlers/blog.rs b/src/handlers/blog.rs
index 0be6dbb..f456542 100644
--- a/src/handlers/blog.rs
+++ b/src/handlers/blog.rs
@@ -56,20 +56,18 @@ pub async fn series_view(
let desc = cfg.series_desc_map.get(&series);
- if posts.len() == 0 {
+ if posts.is_empty() {
(
StatusCode::NOT_FOUND,
tmpl::error(format!("series not found: {series}")),
)
+ } else if let Some(desc) = desc {
+ (StatusCode::OK, tmpl::series_view(&series, desc, &posts))
} else {
- if let Some(desc) = desc {
- (StatusCode::OK, tmpl::series_view(&series, desc, &posts))
- } else {
- (
- StatusCode::INTERNAL_SERVER_ERROR,
- tmpl::error(format!("series metadata in dhall not found: {series}")),
- )
- }
+ (
+ StatusCode::INTERNAL_SERVER_ERROR,
+ tmpl::error(format!("series metadata in dhall not found: {series}")),
+ )
}
}
@@ -84,7 +82,7 @@ pub async fn post_view(
for post in &state.blog {
if post.link == want_link {
- want = Some(&post);
+ want = Some(post);
}
}
@@ -102,7 +100,7 @@ pub async fn post_view(
.with_label_values(&[name.clone().as_str()])
.inc();
let body = maud::PreEscaped(&post.body_html);
- Ok((StatusCode::OK, tmpl::blog::blog(&post, body, referer)))
+ Ok((StatusCode::OK, tmpl::blog::blog(post, body, referer)))
}
}
}
diff --git a/src/handlers/feeds.rs b/src/handlers/feeds.rs
index bc3d861..c55dcb7 100644
--- a/src/handlers/feeds.rs
+++ b/src/handlers/feeds.rs
@@ -16,8 +16,8 @@ lazy_static! {
&["kind"]
)
.unwrap();
- pub static ref ETAG: String = format!(r#"W/"{}""#, uuid::Uuid::new_v4().to_string().replace("-", ""));
- pub static ref CACHEBUSTER: String = uuid::Uuid::new_v4().to_string().replace("-", "");
+ pub static ref ETAG: String = format!(r#"W/"{}""#, uuid::Uuid::new_v4().to_string().replace('-', ""));
+ pub static ref CACHEBUSTER: String = uuid::Uuid::new_v4().to_string().replace('-', "");
}
#[instrument(skip(state))]
@@ -31,7 +31,7 @@ pub async fn jsonfeed(Extension(state): Extension<Arc<State>>) -> Json<xe_jsonfe
#[axum_macros::debug_handler]
pub async fn new_post(Extension(state): Extension<Arc<State>>) -> Result<Json<NewPost>> {
let state = state.clone();
- let p: Post = state.everything.iter().next().unwrap().clone();
+ let p: Post = state.everything.get(0).unwrap().clone();
Ok(Json(p.new_post))
}
diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs
index dba9275..c141560 100644
--- a/src/handlers/mod.rs
+++ b/src/handlers/mod.rs
@@ -139,7 +139,7 @@ pub async fn patrons(Extension(state): Extension<Arc<State>>) -> (StatusCode, Ma
StatusCode::INTERNAL_SERVER_ERROR,
tmpl::error("Patreon API config is broken, no patrons in ram"),
),
- Some(patrons) => (StatusCode::IM_A_TEAPOT, tmpl::patrons(&patrons)),
+ Some(patrons) => (StatusCode::IM_A_TEAPOT, tmpl::patrons(patrons)),
}
}
diff --git a/src/handlers/streams.rs b/src/handlers/streams.rs
index 3eb3b27..2818944 100644
--- a/src/handlers/streams.rs
+++ b/src/handlers/streams.rs
@@ -20,7 +20,6 @@ lazy_static! {
}
pub async fn list(Extension(state): Extension<Arc<State>>) -> Markup {
- let state = state.clone();
let cfg = state.cfg.clone();
crate::tmpl::base(
diff --git a/src/main.rs b/src/main.rs
index 90f8fba..79e1904 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::upper_case_acronyms, clippy::from_over_into)]
+
#[macro_use]
extern crate tracing;
diff --git a/src/post/mod.rs b/src/post/mod.rs
index 2338365..fb7d3bd 100644
--- a/src/post/mod.rs
+++ b/src/post/mod.rs
@@ -70,7 +70,7 @@ impl Into<xe_jsonfeed::Item> for Post {
tags.append(&mut meta_tags);
}
- if tags.len() != 0 {
+ if tags.is_empty() {
result = result.tags(tags);
}
@@ -84,7 +84,7 @@ impl Into<xe_jsonfeed::Item> for Post {
impl Ord for Post {
fn cmp(&self, other: &Self) -> Ordering {
- self.partial_cmp(&other).unwrap()
+ self.partial_cmp(other).unwrap()
}
}
@@ -115,7 +115,7 @@ async fn read_post(dir: &str, fname: PathBuf, cli: &Option<mi::Client>) -> Resul
let date = NaiveDate::parse_from_str(&front_matter.clone().date, "%Y-%m-%d")
.map_err(|why| eyre!("error parsing date in {:?}: {}", fname, why))?;
let link = format!("{}/{}", dir, fname.file_stem().unwrap().to_str().unwrap());
- let body_html = xesite_markdown::render(&body)
+ let body_html = xesite_markdown::render(body)
.wrap_err_with(|| format!("can't parse markdown for {:?}", fname))?;
let date: DateTime<FixedOffset> = DateTime::<Utc>::from_utc(
NaiveDateTime::new(date, NaiveTime::from_hms_opt(0, 0, 0).unwrap()),
@@ -134,8 +134,7 @@ async fn read_post(dir: &str, fname: PathBuf, cli: &Option<mi::Client>) -> Resul
.filter(|wm| {
wm.title.as_ref().unwrap_or(&"".to_string()) != &"Bridgy Response".to_string()
})
- .map(|wm| {
- let mut wm = wm.clone();
+ .map(|mut wm| {
wm.title = Some(
mastodon2text::convert(
wm.title.as_ref().unwrap_or(&"".to_string()).to_string(),
@@ -149,7 +148,7 @@ async fn read_post(dir: &str, fname: PathBuf, cli: &Option<mi::Client>) -> Resul
};
let time_taken = estimated_read_time::text(
- &body,
+ body,
&estimated_read_time::Options::new()
.technical_document(true)
.technical_difficulty(1)
@@ -177,7 +176,7 @@ async fn read_post(dir: &str, fname: PathBuf, cli: &Option<mi::Client>) -> Resul
pub async fn load(dir: &str) -> Result<Vec<Post>> {
let cli = match std::env::var("MI_TOKEN") {
- Ok(token) => mi::Client::new(token.to_string(), crate::APPLICATION_NAME.to_string()).ok(),
+ Ok(token) => mi::Client::new(token, crate::APPLICATION_NAME.to_string()).ok(),
Err(_) => None,
};
@@ -191,7 +190,7 @@ pub async fn load(dir: &str) -> Result<Vec<Post>> {
.map(Result::unwrap)
.collect();
- if result.len() == 0 {
+ if result.is_empty() {
Err(eyre!("no posts loaded"))
} else {
result.sort();
diff --git a/src/tmpl/blog.rs b/src/tmpl/blog.rs
index 15af3b5..ea35fdb 100644
--- a/src/tmpl/blog.rs
+++ b/src/tmpl/blog.rs
@@ -29,11 +29,11 @@ fn post_metadata(post: &Post) -> Markup {
}
fn share_button(post: &Post) -> Markup {
- return xeact_component("MastodonShareButton", serde_json::json!({
+ xeact_component("MastodonShareButton", serde_json::json!({
"title": post.front_matter.title,
"series": post.front_matter.series,
"tags": post.front_matter.tags.as_ref().unwrap_or(&Vec::new())
- }));
+ }))
}
fn twitch_vod(post: &Post) -> Markup {
diff --git a/src/tmpl/mod.rs b/src/tmpl/mod.rs
index 1941d94..92faacb 100644
--- a/src/tmpl/mod.rs
+++ b/src/tmpl/mod.rs
@@ -8,7 +8,7 @@ pub mod blog;
pub mod nag;
lazy_static! {
- static ref CACHEBUSTER: String = uuid::Uuid::new_v4().to_string().replace("-", "");
+ static ref CACHEBUSTER: String = uuid::Uuid::new_v4().to_string().replace('-', "");
}
pub fn base(title: Option<&str>, styles: Option<&str>, content: Markup) -> Markup {
@@ -133,7 +133,7 @@ pub fn base(title: Option<&str>, styles: Option<&str>, content: Markup) -> Marku
}
}
-pub fn post_index(posts: &Vec<Post>, title: &str, show_extra: bool) -> Markup {
+pub fn post_index(posts: &[Post], title: &str, show_extra: bool) -> Markup {
let today = Utc::now().date_naive();
base(
Some(title),
@@ -424,7 +424,7 @@ pub fn index(xe: &Author, projects: &Vec<Link>) -> Markup {
link rel="authorization_endpoint" href="https://idp.christine.website/auth";
link rel="canonical" href="https://xeiaso.net/";
meta name="google-site-verification" content="rzs9eBEquMYr9Phrg0Xm0mIwFjDBcbdgJ3jF6Disy-k";
- (schema_person(&xe))
+ (schema_person(xe))
meta name="twitter:card" content="summary";
meta name="twitter:site" content="@theprincessxena";