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

View File

@@ -52,13 +52,13 @@ impl fmt::Display for Error {
match self {
Error::ReadFile { path, source } => {
write!(f, "failed to read {}: {}", path.display(), source)
}
},
Error::Frontmatter { path, message } => {
write!(f, "invalid frontmatter in {}: {}", path.display(), message)
}
},
Error::WriteFile { path, source } => {
write!(f, "failed to write {}: {}", path.display(), source)
}
},
Error::CreateDir { path, source } => {
write!(
f,
@@ -66,17 +66,17 @@ impl fmt::Display for Error {
path.display(),
source
)
}
},
Error::ContentDirNotFound(path) => {
write!(f, "content directory not found: {}", path.display())
}
},
Error::Config { path, message } => {
write!(f, "invalid config in {}: {}", path.display(), message)
}
},
Error::TemplateLoad(e) => write!(f, "failed to load templates: {}", e),
Error::TemplateRender { template, .. } => {
write!(f, "failed to render template '{}'", template)
}
},
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::Filename(_) | InjectionLanguageMarker::Shebang(_) => {
return None;
}
},
};
self.name_to_lang
.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("\">");
}
}
},
}
}

View File

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

View File

@@ -2,7 +2,7 @@
//!
//! 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.
///

View File

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