aboutsummaryrefslogtreecommitdiff
path: root/src/modules/blog
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/blog
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/blog')
-rw-r--r--src/modules/blog/module.rs50
1 files changed, 18 insertions, 32 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")