aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-04-16 15:12:19 -0700
committerFuwn <[email protected]>2023-04-16 15:12:19 -0700
commite65d780247888b12217abfaca807e180f1e0eb33 (patch)
tree0b831d2e3ab70d10e06a0b2b569d20eb928ccc50 /src/modules
parentchore(robots): remove unused module (diff)
downloadlocus-e65d780247888b12217abfaca807e180f1e0eb33.tar.xz
locus-e65d780247888b12217abfaca807e180f1e0eb33.zip
deps(rust): bump to nightly-2023-04-15
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/blog/module.rs50
-rw-r--r--src/modules/remarks.rs2
-rw-r--r--src/modules/router/translate/deepl.rs2
-rw-r--r--src/modules/router/translate/module.rs8
-rw-r--r--src/modules/search.rs2
-rw-r--r--src/modules/skills.rs2
6 files changed, 24 insertions, 42 deletions
diff --git a/src/modules/blog/module.rs b/src/modules/blog/module.rs
index 41fcf86..a5cbcba 100644
--- a/src/modules/blog/module.rs
+++ b/src/modules/blog/module.rs
@@ -89,13 +89,8 @@ pub fn module(router: &mut windmark::Router) {
// https://gist.github.com/jpastuszek/2704f3c5a3864b05c48ee688d0fd21d7
let mut c = s.chars();
- match c.next() {
- None => String::new(),
- Some(f) =>
- f.to_uppercase()
- .chain(c.flat_map(char::to_lowercase))
- .collect(),
- }
+ c.next().map_or_else(String::new, |f| f.to_uppercase()
+ .chain(c.flat_map(char::to_lowercase)).collect())
})
.collect::<Vec<_>>()
.join(" "),
@@ -118,11 +113,7 @@ pub fn module(router: &mut windmark::Router) {
.map(|(title, entries)| {
let config: Option<Blog> =
entries.get("blog.json").and_then(|content| {
- if let Ok(config) = Blog::from_string(content) {
- Some(config)
- } else {
- None
- }
+ Blog::from_string(content).ok()
});
let name = config
.clone()
@@ -156,11 +147,7 @@ pub fn module(router: &mut windmark::Router) {
let fixed_blog_name_clone_2 = fixed_blog_name.clone();
let config: Option<Blog> =
entries.remove_entry("blog.json").and_then(|(_, content)| {
- if let Ok(config) = Blog::from_string(&content) {
- Some(config)
- } else {
- None
- }
+ Blog::from_string(&content).ok()
});
let entries_clone = entries.clone();
let name = config
@@ -181,17 +168,17 @@ pub fn module(router: &mut windmark::Router) {
xml.add_field("title", &name);
xml.add_field(
"link",
- &format!("gemini://fuwn.me/blog/{}", fixed_blog_name),
+ &format!("gemini://fuwn.me/blog/{fixed_blog_name}"),
);
xml.add_field("description", &description);
xml.add_field("generator", "locus");
xml.add_field("lastBuildDate", &chrono::Local::now().to_rfc2822());
- xml.add_link(&format!("gemini://fuwn.me/blog/{}.xml", fixed_blog_name));
+ xml.add_link(&format!("gemini://fuwn.me/blog/{fixed_blog_name}.xml"));
track_mount(
router,
- &format!("/blog/{}", fixed_blog_name),
- &format!("{} ― {}", name, description),
+ &format!("/blog/{fixed_blog_name}"),
+ &format!("{name} ― {description}"),
move |context| {
let fixed_blog_name = fixed_blog_name_clone.clone();
@@ -203,8 +190,8 @@ pub fn module(router: &mut windmark::Router) {
entries_clone.len(),
description,
entries_clone
- .iter()
- .map(|(title, _)| title.clone())
+ .keys()
+ .map(Clone::clone)
.collect::<Vec<_>>()
.into_iter()
.map(|title| {
@@ -228,10 +215,10 @@ pub fn module(router: &mut windmark::Router) {
let post = postish
.description()
.clone()
- .unwrap_or_else(|| "".to_string());
+ .unwrap_or_default();
if post.is_empty() {
- "".to_string()
+ String::new()
} else {
format!(" ― {}", post)
}
@@ -248,11 +235,10 @@ pub fn module(router: &mut windmark::Router) {
);
for (title, contents) in entries {
- let header = if let Ok(header) = construct_header(&config, &title) {
- header
- } else {
- ("".to_string(), "".to_string())
- };
+ let header = construct_header(&config, &title).map_or_else(
+ |_| (String::new(), String::new()),
+ |header| header,
+ );
let fixed_blog_name = fixed_blog_name_clone_2.clone();
xml.add_item(&{
@@ -311,8 +297,8 @@ pub fn module(router: &mut windmark::Router) {
track_mount(
router,
- &format!("/blog/{}.xml", fixed_blog_name),
- &format!("Really Simple Syndication for the {} blog", name),
+ &format!("/blog/{fixed_blog_name}.xml"),
+ &format!("Really Simple Syndication for the {name} blog"),
move |_| {
windmark::Response::success(xml.to_string())
.with_mime("text/rss+xml")
diff --git a/src/modules/remarks.rs b/src/modules/remarks.rs
index e683d2a..29ad684 100644
--- a/src/modules/remarks.rs
+++ b/src/modules/remarks.rs
@@ -49,7 +49,7 @@ pub fn module(router: &mut windmark::Router) {
r.remark,
r.created,
r.edited.as_ref().map_or_else(
- || "".to_string(),
+ String::new,
|edited| format!(" Edited {}", edited)
)
)
diff --git a/src/modules/router/translate/deepl.rs b/src/modules/router/translate/deepl.rs
index b1767e8..9398118 100644
--- a/src/modules/router/translate/deepl.rs
+++ b/src/modules/router/translate/deepl.rs
@@ -119,6 +119,6 @@ pub fn language_code_to_language_name(language_code: &str) -> String {
"uk" => "Ukrainian".to_string(),
"vi" => "Vietnamese".to_string(),
"cy" => "Welsh".to_string(),
- _ => format!("Unknown ({})", language_code),
+ _ => format!("Unknown ({language_code})"),
}
}
diff --git a/src/modules/router/translate/module.rs b/src/modules/router/translate/module.rs
index 70e4829..f6b2367 100644
--- a/src/modules/router/translate/module.rs
+++ b/src/modules/router/translate/module.rs
@@ -53,15 +53,11 @@ where
"=> {to}?translate={}{}",
language.as_ref(),
text.clone().map_or_else(
- || "".to_string(),
+ String::new,
|text| {
format!(
" {}",
- if let Ok(text) = translate(&text, language.as_ref()) {
- text.text()
- } else {
- text
- }
+ translate(&text, language.as_ref()).map_or(text, |text| text.text()),
)
}
)
diff --git a/src/modules/search.rs b/src/modules/search.rs
index 28593e0..5514b2f 100644
--- a/src/modules/search.rs
+++ b/src/modules/search.rs
@@ -122,7 +122,7 @@ pub(super) fn module(router: &mut windmark::Router) {
.skip(2);
lines.next().map_or_else(
- || "".to_string(),
+ String::new,
|first_line| {
let mut context_lines = lines.skip_while(|l| {
!l.to_lowercase().contains(&query.0.to_string())
diff --git a/src/modules/skills.rs b/src/modules/skills.rs
index 182bf15..ce97f3e 100644
--- a/src/modules/skills.rs
+++ b/src/modules/skills.rs
@@ -43,7 +43,7 @@ pub fn module(router: &mut windmark::Router) {
"* {}{}",
item,
areas.clone().map_or_else(
- || "".to_string(),
+ String::new,
|known_areas| format!(": {}", known_areas.join(", "))
)
)