Skip to content

Commit 55925d7

Browse files
authored
Merge pull request #46 from tsugumi-sys/codex/fix-lint-errors-in-rust-code
Fix clippy format args
2 parents 294316a + cee4bfc commit 55925d7

File tree

12 files changed

+93
-87
lines changed

12 files changed

+93
-87
lines changed

config/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ impl MejiroConfig {
2727
/// Load blog configuration from YAML
2828
pub fn load_config(config_path: &str) -> Self {
2929
let contents = fs::read_to_string(config_path).unwrap_or_else(|e| {
30-
panic!("❌ Could not read the config file: {} ({})", config_path, e);
30+
panic!("❌ Could not read the config file: {config_path} ({e})");
3131
});
3232

3333
serde_yaml::from_str(&contents).unwrap_or_else(|e| {
34-
panic!("❌ Failed to parse YAML file '{}': {}", config_path, e);
34+
panic!("❌ Failed to parse YAML file '{config_path}': {e}");
3535
})
3636
}
3737

@@ -81,7 +81,7 @@ impl MejiroConfig {
8181
println!("\n🎉 Your Mejiro Blog structure:");
8282
for (name, desc) in entries {
8383
let padding = " ".repeat(longest_len - name.len() + 1);
84-
println!("├── {}{}# {}", name, padding, desc);
84+
println!("├── {name}{padding}# {desc}");
8585
}
8686
}
8787

html/src/aside.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ pub fn aside_html(
88
r#"
99
<aside>
1010
<div class="logo">
11-
<img src="{}" alt="Logo">
12-
<span>{}</span>
11+
<img src="{icon_path}" alt="Logo">
12+
<span>{owner_name}</span>
1313
</div>
1414
<nav class="links">
1515
<a href="/">Home</a>
16-
<a href="{}">GitHub</a>
17-
<a href="{}">LinkedIn</a>
16+
<a href="{owner_github_link}">GitHub</a>
17+
<a href="{owner_linkedin_link}">LinkedIn</a>
1818
</nav>
1919
</aside>
20-
"#,
21-
icon_path, owner_name, owner_github_link, owner_linkedin_link
20+
"#
2221
)
2322
}

html/src/footer.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ pub fn footer_html(site_title: &str) -> String {
55
format!(
66
r#"
77
<footer>
8-
<p>&copy; {} {}</p>
8+
<p>&copy; {current_year} {site_title}</p>
99
</footer>
10-
"#,
11-
current_year, site_title
10+
"#
1211
)
1312
}

html/src/icon.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,5 @@ pub fn icon_html(icon_path: &str) -> String {
1313
})
1414
.unwrap_or("image/png");
1515

16-
format!(
17-
r#"<link rel="icon" href="{}" type="{}">"#,
18-
icon_path, icon_type
19-
)
16+
format!(r#"<link rel="icon" href="{icon_path}" type="{icon_type}">"#)
2017
}

html/src/index.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ pub fn index_html(
1515
<head>
1616
<meta charset="UTF-8" />
1717
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
18-
<title>{} Blog</title>
19-
<link rel="stylesheet" href="{}">
20-
{}
18+
<title>{owner_name} Blog</title>
19+
<link rel="stylesheet" href="{csv_file_path}">
20+
{icon_html}
2121
</head>
2222
<body>
2323
<div class="container">
24-
{}
24+
{aside_html}
2525
<main>
2626
<div class="search-bar-wrapper">
2727
<i id="search-trigger" class="fas fa-search"></i>
@@ -33,37 +33,42 @@ pub fn index_html(
3333
3434
<h1>Posts</h1>
3535
<ul id="post-list">
36-
"#,
37-
owner_name, csv_file_path, icon_html, aside_html
36+
"#
3837
);
3938

4039
// Loop through the posts and build the list
4140
for post in posts {
42-
let summary_html = post.meta.tldr.as_ref().map_or(String::new(), |s| {
43-
format!(r#"<p class="summary">{}</p>"#, s)
44-
});
41+
let summary_html = post
42+
.meta
43+
.tldr
44+
.as_ref()
45+
.map_or(String::new(), |s| format!(r#"<p class="summary">{s}</p>"#));
4546

4647
let topics_html = if !post.meta.topics.is_empty() {
4748
let topics = post.meta.topics.join(", ");
48-
format!(r#"<p class="topics">Tags: {}</p>"#, topics)
49+
format!(r#"<p class="topics">Tags: {topics}</p>"#)
4950
} else {
5051
String::new()
5152
};
5253

5354
let date_html = format!(
54-
r#"<p class="published-at">Published at: {}</p>"#,
55-
post.meta.published_at
55+
r#"<p class="published-at">Published at: {published_at}</p>"#,
56+
published_at = post.meta.published_at
5657
);
5758

5859
index_html.push_str(&format!(
5960
r#" <li>
60-
<a href="posts/{}.html"><strong>{}</strong></a>
61-
{}
62-
{}
63-
{}
61+
<a href="posts/{name}.html"><strong>{title}</strong></a>
62+
{summary_html}
63+
{topics_html}
64+
{date_html}
6465
</li>
6566
"#,
66-
post.name, post.meta.title, summary_html, topics_html, date_html
67+
name = post.name,
68+
title = post.meta.title,
69+
summary_html = summary_html,
70+
topics_html = topics_html,
71+
date_html = date_html
6772
));
6873
}
6974

html/src/metadata.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ impl std::fmt::Display for BlogParseError {
1717
BlogParseError::MetadataNotFound => {
1818
write!(f, "The markdown file is missing a metadata (YAML) header.")
1919
}
20-
BlogParseError::YamlParseError(msg) => write!(f, "Failed to parse metadata: {}", msg),
21-
BlogParseError::IoError(msg) => write!(f, "File error: {}", msg),
20+
BlogParseError::YamlParseError(msg) => write!(f, "Failed to parse metadata: {msg}"),
21+
BlogParseError::IoError(msg) => write!(f, "File error: {msg}"),
2222
}
2323
}
2424
}
@@ -131,11 +131,10 @@ This is the blog post content.
131131
msg.contains("while parsing a flow sequence")
132132
|| msg.contains("did not find expected ',' or ']'")
133133
|| msg.contains("expected ',' or ']'"),
134-
"Unexpected error message: {}",
135-
msg
134+
"Unexpected error message: {msg}",
136135
);
137136
}
138-
_ => panic!("Expected YamlParseError, got {:?}", result),
137+
_ => panic!("Expected YamlParseError, got {result:?}"),
139138
}
140139
}
141140

html/src/post.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ pub fn post_html(
1010
// Generate the header for the post
1111
let header_html = format!(
1212
r#"<header>
13-
<h1>{}</h1>
13+
<h1>{title}</h1>
1414
<div class="post-meta">
15-
<span class="published-at">{}</span>
16-
{}
15+
<span class="published-at">{published_at}</span>
16+
{summary}
1717
</div>
1818
</header>"#,
19-
post.meta.title,
20-
post.meta.published_at,
21-
if let Some(tldr) = &post.meta.tldr {
22-
format!(r#"<p class="summary">{}</p>"#, tldr)
19+
title = post.meta.title,
20+
published_at = post.meta.published_at,
21+
summary = if let Some(tldr) = &post.meta.tldr {
22+
format!(r#"<p class="summary">{tldr}</p>"#)
2323
} else {
2424
String::new()
2525
}
@@ -32,30 +32,30 @@ pub fn post_html(
3232
<head>
3333
<meta charset="UTF-8" />
3434
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
35-
<title>{}</title>
36-
<link rel="stylesheet" href="{}">
37-
{}
35+
<title>{title}</title>
36+
<link rel="stylesheet" href="{css_file_path}">
37+
{icon_html}
3838
</head>
3939
<body>
4040
<div class="container">
41-
{}
41+
{aside_html}
4242
<main>
43-
{}
43+
{header_html}
4444
<article>
45-
{}
45+
{body}
4646
</article>
4747
</main>
4848
</div>
49-
{}
49+
{footer_html}
5050
</body>
5151
</html>
5252
"#,
53-
post.meta.title,
54-
css_file_path,
55-
icon_html,
56-
aside_html,
57-
header_html,
58-
post.html_body,
59-
footer_html
53+
title = post.meta.title,
54+
css_file_path = css_file_path,
55+
icon_html = icon_html,
56+
aside_html = aside_html,
57+
header_html = header_html,
58+
body = post.html_body,
59+
footer_html = footer_html
6060
)
6161
}

mejiro-cli/src/compile.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ pub fn compile(input_dir: &str, output_dir: &str, config_path: &str) {
4848
match Post::from_markdown_file(entry.path()) {
4949
Ok(Some(post)) => posts.push(post),
5050
Ok(None) => {
51-
println!("Skipping unpublished post: {}", entry.path().display());
51+
let path = entry.path().display();
52+
println!("Skipping unpublished post: {path}");
5253
}
5354
Err(e) => {
54-
eprintln!("Error parsing {}: {}", entry.path().display(), e);
55+
let path = entry.path().display();
56+
eprintln!("Error parsing {path}: {e}");
5557
}
5658
}
5759
}
5860
posts.sort_by(|a, b| b.meta.published_at.cmp(&a.meta.published_at));
5961

6062
// Build post pages
61-
let icon_path_rel = format!("../{}", icon_file_name);
63+
let icon_path_rel = format!("../{icon_file_name}");
6264
let aside = html::aside_html(
6365
&config.owner.name,
6466
&config.owner.github_link,
@@ -90,7 +92,7 @@ pub fn compile(input_dir: &str, output_dir: &str, config_path: &str) {
9092

9193
let post_paths: Vec<String> = posts
9294
.iter()
93-
.map(|post| format!("{}.html", post.name))
95+
.map(|post| format!("{name}.html", name = post.name))
9496
.collect();
9597

9698
println!("\nOutput directory structure:");
@@ -105,15 +107,16 @@ pub fn compile(input_dir: &str, output_dir: &str, config_path: &str) {
105107
// Show top/bottom posts only if many
106108
if post_paths.len() > 10 {
107109
for path in &post_paths[..3] {
108-
println!("│ ├── {}", path);
110+
println!("│ ├── {path}");
109111
}
110-
println!("│ ├── ... ({} posts omitted)", post_paths.len() - 6);
112+
let omitted = post_paths.len() - 6;
113+
println!("│ ├── ... ({omitted} posts omitted)");
111114
for path in &post_paths[post_paths.len() - 3..] {
112-
println!("│ ├── {}", path);
115+
println!("│ ├── {path}");
113116
}
114117
} else {
115118
for path in &post_paths {
116-
println!("│ ├── {}", path);
119+
println!("│ ├── {path}");
117120
}
118121
}
119122

@@ -126,11 +129,11 @@ fn css_filename_with_hash(css_path: &Path) -> Option<String> {
126129
let mut hasher = Sha256::new();
127130
hasher.update(&bytes);
128131
let hash = hasher.finalize();
129-
let hash_hex = format!("{:x}", hash);
132+
let hash_hex = format!("{hash:x}");
130133

131-
Some(format!("style.{}.css", &hash_hex[..8]))
134+
Some(format!("style.{hash}.css", hash = &hash_hex[..8]))
132135
} else {
133-
eprintln!("CSS file not found: {:?}", css_path);
136+
eprintln!("CSS file not found: {css_path:?}");
134137
None
135138
}
136139
}
@@ -139,7 +142,7 @@ fn copy_file(src: &Path, dest: &Path, description: &str) -> std::io::Result<()>
139142
if src.exists() {
140143
fs::copy(src, dest)?;
141144
} else {
142-
eprintln!("{} not found: {:?}", description, src);
145+
eprintln!("{description} not found: {src:?}");
143146
}
144147
Ok(())
145148
}
@@ -157,7 +160,7 @@ fn copy_images(src_dir: &Path, dest_dir: &Path) {
157160
}
158161
}
159162
} else {
160-
eprintln!("Images directory not found: {:?}", src_dir);
163+
eprintln!("Images directory not found: {src_dir:?}");
161164
}
162165
}
163166

@@ -170,10 +173,12 @@ fn build_post_pages(
170173
css_filename: &str,
171174
) {
172175
for post in posts {
173-
let output_path = output_dir.join("posts").join(format!("{}.html", post.name));
176+
let output_path = output_dir
177+
.join("posts")
178+
.join(format!("{name}.html", name = post.name));
174179
fs::create_dir_all(output_path.parent().unwrap()).unwrap();
175180

176-
let css_relative_path = format!("../{}", css_filename);
181+
let css_relative_path = format!("../{css_filename}");
177182
let post_html = html::post_html(post, aside, footer, icon, &css_relative_path);
178183
fs::write(&output_path, post_html).unwrap();
179184
}

mejiro-cli/src/image.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ pub fn add(config_path: &str, image_path: &str) -> io::Result<()> {
1111
fs::create_dir_all(dest_dir)?;
1212
let dest = dest_dir.join(src.file_name().unwrap());
1313
fs::copy(src, &dest)?;
14-
println!("✅ Added image: {}", dest.display());
14+
let path = dest.display();
15+
println!("✅ Added image: {path}");
1516
Ok(())
1617
}
1718

1819
pub fn list(config_path: &str) {
1920
let cfg = MejiroConfig::load_config(config_path);
2021
let dir = Path::new(&cfg.images_dir);
2122
if !dir.exists() {
22-
eprintln!("❌ images directory not found: {}", dir.display());
23+
let path = dir.display();
24+
eprintln!("❌ images directory not found: {path}");
2325
return;
2426
}
2527
for entry in WalkDir::new(dir)
@@ -28,7 +30,8 @@ pub fn list(config_path: &str) {
2830
.filter(|e| e.file_type().is_file())
2931
{
3032
if let Ok(rel) = entry.path().strip_prefix(dir) {
31-
println!("{}", rel.display());
33+
let rel_path = rel.display();
34+
println!("{rel_path}");
3235
}
3336
}
3437
}

mejiro-cli/src/list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub fn list(input_dir: &str, all: bool) {
2626
continue;
2727
}
2828
println!("---");
29-
println!("name: {}", name);
29+
println!("name: {name}");
3030
let yaml = serde_yaml::to_string(&meta).unwrap_or_default();
31-
print!("{}", yaml);
31+
print!("{yaml}");
3232
}
3333
}

0 commit comments

Comments
 (0)