chore: add .rustfmt.toml

This commit is contained in:
Timothy DeHerrera
2026-02-05 23:48:08 -07:00
parent 13e728de80
commit f1e3add292
8 changed files with 73 additions and 52 deletions

21
.rustfmt.toml Normal file
View File

@@ -0,0 +1,21 @@
edition = "2024"
newline_style = "unix"
use_field_init_shorthand = true
use_try_shorthand = true
unstable_features = true
comment_width = 100
condense_wildcard_suffixes = true
error_on_line_overflow = true
format_code_in_doc_comments = true
format_macro_bodies = true
format_macro_matchers = true
format_strings = true
group_imports = "StdExternalCrate"
imports_granularity = "Module"
match_block_trailing_comma = true
normalize_doc_attributes = true
reorder_impl_items = true
style_edition = "2024"
wrap_comments = true

View File

@@ -1,7 +1,7 @@
//! Content discovery and frontmatter parsing. //! Content discovery and frontmatter parsing.
use crate::error::{Error, Result}; use crate::error::{Error, Result};
use gray_matter::{engine::YAML, Matter}; use gray_matter::{Matter, engine::YAML};
use serde::Serialize; use serde::Serialize;
use std::fs; use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@@ -116,12 +116,12 @@ impl Content {
// _index.md → parent/index.html (listing pages stay as index.html) // _index.md → parent/index.html (listing pages stay as index.html)
let parent = relative.parent().unwrap_or(Path::new("")); let parent = relative.parent().unwrap_or(Path::new(""));
parent.join("index.html") parent.join("index.html")
} },
_ => { _ => {
// Regular content → parent/slug.html (flat structure) // Regular content → parent/slug.html (flat structure)
let parent = relative.parent().unwrap_or(Path::new("")); let parent = relative.parent().unwrap_or(Path::new(""));
parent.join(format!("{}.html", self.slug)) parent.join(format!("{}.html", self.slug))
} },
} }
} }
} }

View File

@@ -52,13 +52,13 @@ impl fmt::Display for Error {
match self { match self {
Error::ReadFile { path, source } => { Error::ReadFile { path, source } => {
write!(f, "failed to read {}: {}", path.display(), source) write!(f, "failed to read {}: {}", path.display(), source)
} },
Error::Frontmatter { path, message } => { Error::Frontmatter { path, message } => {
write!(f, "invalid frontmatter in {}: {}", path.display(), message) write!(f, "invalid frontmatter in {}: {}", path.display(), message)
} },
Error::WriteFile { path, source } => { Error::WriteFile { path, source } => {
write!(f, "failed to write {}: {}", path.display(), source) write!(f, "failed to write {}: {}", path.display(), source)
} },
Error::CreateDir { path, source } => { Error::CreateDir { path, source } => {
write!( write!(
f, f,
@@ -66,17 +66,17 @@ impl fmt::Display for Error {
path.display(), path.display(),
source source
) )
} },
Error::ContentDirNotFound(path) => { Error::ContentDirNotFound(path) => {
write!(f, "content directory not found: {}", path.display()) write!(f, "content directory not found: {}", path.display())
} },
Error::Config { path, message } => { Error::Config { path, message } => {
write!(f, "invalid config in {}: {}", path.display(), message) write!(f, "invalid config in {}: {}", path.display(), message)
} },
Error::TemplateLoad(e) => write!(f, "failed to load templates: {}", e), Error::TemplateLoad(e) => write!(f, "failed to load templates: {}", e),
Error::TemplateRender { template, .. } => { Error::TemplateRender { template, .. } => {
write!(f, "failed to render template '{}'", template) write!(f, "failed to render template '{}'", template)
} },
Error::CssBundle(msg) => write!(f, "CSS bundle error: {}", msg), Error::CssBundle(msg) => write!(f, "CSS bundle error: {}", msg),
} }
} }

View File

@@ -541,7 +541,7 @@ impl LanguageLoader for SukrLoader {
InjectionLanguageMarker::Match(text) => text.into(), InjectionLanguageMarker::Match(text) => text.into(),
InjectionLanguageMarker::Filename(_) | InjectionLanguageMarker::Shebang(_) => { InjectionLanguageMarker::Filename(_) | InjectionLanguageMarker::Shebang(_) => {
return None; return None;
} },
}; };
self.name_to_lang self.name_to_lang
.get(name.to_lowercase().as_str()) .get(name.to_lowercase().as_str())
@@ -618,7 +618,7 @@ fn render_html<'a>(source: &str, mut highlighter: Highlighter<'a, 'a, SukrLoader
html.push_str(class); html.push_str(class);
html.push_str("\">"); html.push_str("\">");
} }
} },
} }
} }

View File

@@ -45,12 +45,12 @@ fn main() {
} }
std::process::exit(1); std::process::exit(1);
} }
} },
Ok(None) => {} // --help was printed Ok(None) => {}, // --help was printed
Err(e) => { Err(e) => {
eprintln!("error: {e}"); eprintln!("error: {e}");
std::process::exit(1); std::process::exit(1);
} },
} }
} }
@@ -65,17 +65,17 @@ fn parse_args() -> std::result::Result<Option<PathBuf>, String> {
"-h" | "--help" => { "-h" | "--help" => {
print!("{USAGE}"); print!("{USAGE}");
return Ok(None); return Ok(None);
} },
"-c" | "--config" => { "-c" | "--config" => {
if i + 1 >= args.len() { if i + 1 >= args.len() {
return Err("--config requires an argument".to_string()); return Err("--config requires an argument".to_string());
} }
config_path = PathBuf::from(&args[i + 1]); config_path = PathBuf::from(&args[i + 1]);
i += 2; i += 2;
} },
arg => { arg => {
return Err(format!("unknown argument: {arg}")); return Err(format!("unknown argument: {arg}"));
} },
} }
} }
@@ -118,7 +118,7 @@ fn run(config_path: &Path) -> Result<()> {
"blog" => { "blog" => {
// Blog: sort by date, newest first // Blog: sort by date, newest first
items.sort_by(|a, b| b.frontmatter.date.cmp(&a.frontmatter.date)); items.sort_by(|a, b| b.frontmatter.date.cmp(&a.frontmatter.date));
} },
"projects" => { "projects" => {
// Projects: sort by weight // Projects: sort by weight
items.sort_by(|a, b| { items.sort_by(|a, b| {
@@ -127,7 +127,7 @@ fn run(config_path: &Path) -> Result<()> {
.unwrap_or(DEFAULT_WEIGHT_HIGH) .unwrap_or(DEFAULT_WEIGHT_HIGH)
.cmp(&b.frontmatter.weight.unwrap_or(DEFAULT_WEIGHT_HIGH)) .cmp(&b.frontmatter.weight.unwrap_or(DEFAULT_WEIGHT_HIGH))
}); });
} },
_ => { _ => {
// Default: sort by weight then title // Default: sort by weight then title
items.sort_by(|a, b| { items.sort_by(|a, b| {
@@ -137,7 +137,7 @@ fn run(config_path: &Path) -> Result<()> {
.cmp(&b.frontmatter.weight.unwrap_or(DEFAULT_WEIGHT)) .cmp(&b.frontmatter.weight.unwrap_or(DEFAULT_WEIGHT))
.then_with(|| a.frontmatter.title.cmp(&b.frontmatter.title)) .then_with(|| a.frontmatter.title.cmp(&b.frontmatter.title))
}); });
} },
} }
// Render individual content pages for all sections // Render individual content pages for all sections

View File

@@ -2,7 +2,7 @@
//! //!
//! Converts LaTeX math expressions to HTML at build-time. //! Converts LaTeX math expressions to HTML at build-time.
use katex::{render_to_string, KatexContext, Settings}; use katex::{KatexContext, Settings, render_to_string};
/// Render a LaTeX math expression to HTML. /// Render a LaTeX math expression to HTML.
/// ///

View File

@@ -1,7 +1,7 @@
//! Markdown to HTML rendering via pulldown-cmark with syntax highlighting. //! Markdown to HTML rendering via pulldown-cmark with syntax highlighting.
use crate::escape::{code_escape, html_escape}; use crate::escape::{code_escape, html_escape};
use crate::highlight::{highlight_code, Language}; use crate::highlight::{Language, highlight_code};
use pulldown_cmark::{CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag, TagEnd}; use pulldown_cmark::{CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag, TagEnd};
use serde::Serialize; use serde::Serialize;
@@ -52,22 +52,22 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec<Anchor>) {
} else { } else {
Some(lang_str.to_string()) Some(lang_str.to_string())
} }
} },
CodeBlockKind::Indented => None, CodeBlockKind::Indented => None,
}; };
in_code_block = true; in_code_block = true;
code_block_content.clear(); code_block_content.clear();
} },
Event::Text(text) if in_code_block => { Event::Text(text) if in_code_block => {
// Accumulate code block content // Accumulate code block content
code_block_content.push_str(&text); code_block_content.push_str(&text);
} },
Event::Text(text) if image_alt_content.is_some() => { Event::Text(text) if image_alt_content.is_some() => {
// Accumulate image alt text // Accumulate image alt text
if let Some(ref mut alt) = image_alt_content { if let Some(ref mut alt) = image_alt_content {
alt.push_str(&text); alt.push_str(&text);
} }
} },
Event::End(TagEnd::CodeBlock) => { Event::End(TagEnd::CodeBlock) => {
// Render the code block with highlighting // Render the code block with highlighting
let lang_str = code_block_lang.as_deref().unwrap_or(""); let lang_str = code_block_lang.as_deref().unwrap_or("");
@@ -79,13 +79,13 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec<Anchor>) {
html_output.push_str("<div class=\"mermaid-diagram\">\n"); html_output.push_str("<div class=\"mermaid-diagram\">\n");
html_output.push_str(&svg); html_output.push_str(&svg);
html_output.push_str("\n</div>\n"); html_output.push_str("\n</div>\n");
} },
Err(e) => { Err(e) => {
eprintln!("mermaid render error: {e}"); eprintln!("mermaid render error: {e}");
html_output.push_str("<pre class=\"mermaid-error\"><code>"); html_output.push_str("<pre class=\"mermaid-error\"><code>");
html_output.push_str(&html_escape(&code_block_content)); html_output.push_str(&html_escape(&code_block_content));
html_output.push_str("</code></pre>\n"); html_output.push_str("</code></pre>\n");
} },
} }
} else { } else {
// Code blocks: syntax highlighting // Code blocks: syntax highlighting
@@ -111,29 +111,29 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec<Anchor>) {
code_block_lang = None; code_block_lang = None;
in_code_block = false; in_code_block = false;
code_block_content.clear(); code_block_content.clear();
} },
Event::Text(text) if heading_level.is_some() => { Event::Text(text) if heading_level.is_some() => {
// Accumulate heading text // Accumulate heading text
heading_text.push_str(&text); heading_text.push_str(&text);
html_output.push_str(&html_escape(&text)); html_output.push_str(&html_escape(&text));
} },
Event::Text(text) => { Event::Text(text) => {
// Regular text outside code blocks // Regular text outside code blocks
html_output.push_str(&html_escape(&text)); html_output.push_str(&html_escape(&text));
} },
Event::Code(text) => { Event::Code(text) => {
// Inline code // Inline code
html_output.push_str("<code>"); html_output.push_str("<code>");
html_output.push_str(&html_escape(&text)); html_output.push_str(&html_escape(&text));
html_output.push_str("</code>"); html_output.push_str("</code>");
} },
Event::Start(Tag::Image { Event::Start(Tag::Image {
dest_url, title, .. dest_url, title, ..
}) => { }) => {
// Begin accumulating alt text; defer rendering to End event // Begin accumulating alt text; defer rendering to End event
image_alt_content = Some(String::new()); image_alt_content = Some(String::new());
image_attrs = Some((dest_url.to_string(), title.to_string())); image_attrs = Some((dest_url.to_string(), title.to_string()));
} },
Event::Start(Tag::Heading { level, .. }) => { Event::Start(Tag::Heading { level, .. }) => {
// Begin accumulating heading text // Begin accumulating heading text
heading_level = Some(level); heading_level = Some(level);
@@ -141,10 +141,10 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec<Anchor>) {
let level_num = level as u8; let level_num = level as u8;
html_output.push_str(&format!("<h{}", level_num)); html_output.push_str(&format!("<h{}", level_num));
// ID will be added at End event after we have the text // ID will be added at End event after we have the text
} },
Event::Start(tag) => { Event::Start(tag) => {
html_output.push_str(&start_tag_to_html(&tag)); html_output.push_str(&start_tag_to_html(&tag));
} },
Event::End(TagEnd::Image) => { Event::End(TagEnd::Image) => {
// Render image with accumulated alt text // Render image with accumulated alt text
let alt = image_alt_content.take().unwrap_or_default(); let alt = image_alt_content.take().unwrap_or_default();
@@ -164,7 +164,7 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec<Anchor>) {
)); ));
} }
} }
} },
Event::End(TagEnd::Heading(level)) => { Event::End(TagEnd::Heading(level)) => {
// Generate slug ID from heading text // Generate slug ID from heading text
let id = slugify(&heading_text); let id = slugify(&heading_text);
@@ -193,28 +193,28 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec<Anchor>) {
heading_level = None; heading_level = None;
heading_text.clear(); heading_text.clear();
} },
Event::End(tag) => { Event::End(tag) => {
html_output.push_str(&end_tag_to_html(&tag)); html_output.push_str(&end_tag_to_html(&tag));
} },
Event::SoftBreak => { Event::SoftBreak => {
html_output.push('\n'); html_output.push('\n');
} },
Event::HardBreak => { Event::HardBreak => {
html_output.push_str("<br />\n"); html_output.push_str("<br />\n");
} },
Event::Rule => { Event::Rule => {
html_output.push_str("<hr />\n"); html_output.push_str("<hr />\n");
} },
Event::Html(html) | Event::InlineHtml(html) => { Event::Html(html) | Event::InlineHtml(html) => {
html_output.push_str(&html); html_output.push_str(&html);
} },
Event::FootnoteReference(name) => { Event::FootnoteReference(name) => {
html_output.push_str(&format!( html_output.push_str(&format!(
"<sup class=\"footnote-ref\"><a href=\"#fn-{}\">{}</a></sup>", "<sup class=\"footnote-ref\"><a href=\"#fn-{}\">{}</a></sup>",
name, name name, name
)); ));
} },
Event::TaskListMarker(checked) => { Event::TaskListMarker(checked) => {
let checkbox = if checked { let checkbox = if checked {
"<input type=\"checkbox\" checked disabled />" "<input type=\"checkbox\" checked disabled />"
@@ -222,7 +222,7 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec<Anchor>) {
"<input type=\"checkbox\" disabled />" "<input type=\"checkbox\" disabled />"
}; };
html_output.push_str(checkbox); html_output.push_str(checkbox);
} },
Event::InlineMath(latex) => match crate::math::render_math(&latex, false) { Event::InlineMath(latex) => match crate::math::render_math(&latex, false) {
Ok(rendered) => html_output.push_str(&rendered), Ok(rendered) => html_output.push_str(&rendered),
Err(e) => { Err(e) => {
@@ -230,20 +230,20 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec<Anchor>) {
html_output.push_str("<code class=\"math-error\">"); html_output.push_str("<code class=\"math-error\">");
html_output.push_str(&html_escape(&latex)); html_output.push_str(&html_escape(&latex));
html_output.push_str("</code>"); html_output.push_str("</code>");
} },
}, },
Event::DisplayMath(latex) => match crate::math::render_math(&latex, true) { Event::DisplayMath(latex) => match crate::math::render_math(&latex, true) {
Ok(rendered) => { Ok(rendered) => {
html_output.push_str("<div class=\"math-display\">\n"); html_output.push_str("<div class=\"math-display\">\n");
html_output.push_str(&rendered); html_output.push_str(&rendered);
html_output.push_str("\n</div>\n"); html_output.push_str("\n</div>\n");
} },
Err(e) => { Err(e) => {
eprintln!("math render error: {e}"); eprintln!("math render error: {e}");
html_output.push_str("<pre class=\"math-error\">"); html_output.push_str("<pre class=\"math-error\">");
html_output.push_str(&html_escape(&latex)); html_output.push_str(&html_escape(&latex));
html_output.push_str("</pre>\n"); html_output.push_str("</pre>\n");
} },
}, },
} }
} }
@@ -274,7 +274,7 @@ fn start_tag_to_html(tag: &Tag) -> String {
Tag::Item => "<li>".to_string(), Tag::Item => "<li>".to_string(),
Tag::FootnoteDefinition(name) => { Tag::FootnoteDefinition(name) => {
format!("<div class=\"footnote\" id=\"fn-{}\">", name) format!("<div class=\"footnote\" id=\"fn-{}\">", name)
} },
Tag::Table(_) => "<table>\n".to_string(), Tag::Table(_) => "<table>\n".to_string(),
Tag::TableHead => "<thead>\n<tr>\n".to_string(), Tag::TableHead => "<thead>\n<tr>\n".to_string(),
Tag::TableRow => "<tr>\n".to_string(), Tag::TableRow => "<tr>\n".to_string(),
@@ -294,7 +294,7 @@ fn start_tag_to_html(tag: &Tag) -> String {
html_escape(title) html_escape(title)
) )
} }
} },
Tag::Image { .. } => String::new(), // Handled separately in main loop Tag::Image { .. } => String::new(), // Handled separately in main loop
Tag::HtmlBlock => String::new(), Tag::HtmlBlock => String::new(),
Tag::MetadataBlock(_) => String::new(), Tag::MetadataBlock(_) => String::new(),
@@ -316,7 +316,7 @@ fn end_tag_to_html(tag: &TagEnd) -> String {
} else { } else {
"</ul>\n".to_string() "</ul>\n".to_string()
} }
} },
TagEnd::Item => "</li>\n".to_string(), TagEnd::Item => "</li>\n".to_string(),
TagEnd::FootnoteDefinition => "</div>\n".to_string(), TagEnd::FootnoteDefinition => "</div>\n".to_string(),
TagEnd::Table => "</table>\n".to_string(), TagEnd::Table => "</table>\n".to_string(),

View File

@@ -215,7 +215,7 @@ fn strip_parens_filter(value: &Value, _args: &HashMap<String, Value>) -> tera::R
s.clone() s.clone()
}; };
Ok(Value::String(result)) Ok(Value::String(result))
} },
_ => Ok(value.clone()), _ => Ok(value.clone()),
} }
} }