From b8ffc4d365592dd105ab120d0cf27630b34b8207 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Tue, 19 Sep 2023 11:24:22 -0500 Subject: [PATCH] style: format with rustfmt --- src/main.rs | 13 ++++++++----- src/markdown/article.rs | 7 +++++-- src/markdown/mod.rs | 23 +++++++++++++++-------- src/page_gen/mod.rs | 2 +- src/page_gen/tags.rs | 22 ++++++++++++++++------ src/tree_sitter_adapter.rs | 6 +++--- 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/main.rs b/src/main.rs index 618e4e2..fc6f9ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use blog::{ TemplateRenderer, }; use clap::Parser; -use std::{collections::HashMap, path::PathBuf}; +use std::{collections::HashMap, fs::DirEntry, path::PathBuf}; use tera::Tera; #[derive(Parser, Debug)] @@ -113,10 +113,13 @@ fn main() -> anyhow::Result<()> { for static_page in static_pages { println!("Rendering Static Page: {}", &static_page); - let rendered_static_page = tera.render(&format!("static/{}", &static_page), &static_context)?; - write_file(&out_path.join(&static_page), rendered_static_page.as_bytes())?; + let rendered_static_page = + tera.render(&format!("static/{}", &static_page), &static_context)?; + write_file( + &out_path.join(&static_page), + rendered_static_page.as_bytes(), + )?; println!("Finished Rendering Static Page: {}", &static_page); - } let base_asset_dir = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/")); @@ -172,4 +175,4 @@ fn write_file(file_path: &PathBuf, contents: &[u8]) -> anyhow::Result<()> { } std::fs::write(file_path, contents).context(format!("Failed to write to {file_path:?}")) -} \ No newline at end of file +} diff --git a/src/markdown/article.rs b/src/markdown/article.rs index 1dae2d4..6c91674 100644 --- a/src/markdown/article.rs +++ b/src/markdown/article.rs @@ -16,7 +16,7 @@ use super::{iter_nodes, MDComrakSettings}; #[derive(Debug, Serialize)] pub struct Article { pub html_content: String, - pub frontmatter: FrontMatter + pub frontmatter: FrontMatter, } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -95,6 +95,9 @@ impl TemplateRenderer for Article { tera_context.insert("article_last_updated", &self.frontmatter.updated); tera_context.insert("article_tags", &self.frontmatter.tags); tera_context.insert("article_content", &self.html_content); - tera.render("article.html", &tera_context).context(format!("Failed to render Article: '{}'", &self.frontmatter.name)) + tera.render("article.html", &tera_context).context(format!( + "Failed to render Article: '{}'", + &self.frontmatter.name + )) } } diff --git a/src/markdown/mod.rs b/src/markdown/mod.rs index 9379f43..3887229 100644 --- a/src/markdown/mod.rs +++ b/src/markdown/mod.rs @@ -1,17 +1,24 @@ -use std::io::{Cursor, Write}; -use comrak::{nodes::{AstNode, Sourcepos}, ComrakOptions, ComrakPlugins, plugins::syntect::{SyntectAdapter, SyntectAdapterBuilder}, adapters::{HeadingAdapter, HeadingMeta}, Anchorizer}; +use comrak::{ + adapters::{HeadingAdapter, HeadingMeta}, + nodes::{AstNode, Sourcepos}, + plugins::syntect::{SyntectAdapter, SyntectAdapterBuilder}, + Anchorizer, ComrakOptions, ComrakPlugins, +}; use lazy_static::lazy_static; +use std::io::{Cursor, Write}; use syntect::highlighting::ThemeSet; pub mod article; lazy_static! { - pub static ref SYNTECT_ADAPTER: SyntectAdapter = - MDComrakSettings::load_theme("kanagawa", &mut Cursor::new(include_bytes!(concat!( + pub static ref SYNTECT_ADAPTER: SyntectAdapter = MDComrakSettings::load_theme( + "kanagawa", + &mut Cursor::new(include_bytes!(concat!( env!("CARGO_MANIFEST_DIR"), "/assets/Kanagawa.tmTheme" - )))) - .expect("Unable to load custom syntax theme!"); + ))) + ) + .expect("Unable to load custom syntax theme!"); } pub fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &mut F) @@ -27,7 +34,7 @@ where struct HeaderLinkAdapter; impl HeadingAdapter for HeaderLinkAdapter { - fn enter( + fn enter( &self, output: &mut dyn Write, heading: &HeadingMeta, @@ -87,4 +94,4 @@ impl MDComrakSettings<'_> { Ok(adapter) } -} \ No newline at end of file +} diff --git a/src/page_gen/mod.rs b/src/page_gen/mod.rs index 62d9bb4..cd4a95d 100644 --- a/src/page_gen/mod.rs +++ b/src/page_gen/mod.rs @@ -8,4 +8,4 @@ pub mod tags; pub struct ArticleLink<'a> { frontmatter: &'a FrontMatter, link: &'a String, -} \ No newline at end of file +} diff --git a/src/page_gen/tags.rs b/src/page_gen/tags.rs index 0c37ab7..99c4e8b 100644 --- a/src/page_gen/tags.rs +++ b/src/page_gen/tags.rs @@ -1,6 +1,6 @@ +use crate::{markdown::article::FrontMatter, TemplateRenderer}; use anyhow::Context; use serde::Serialize; -use crate::{TemplateRenderer, markdown::article::FrontMatter}; pub struct Tags<'a> { tags: &'a Vec<&'a String>, @@ -26,21 +26,27 @@ impl TemplateRenderer for Tags<'_> { #[derive(Serialize)] pub struct ArticleLink<'a> { pub frontmatter: &'a FrontMatter, - pub link: &'a String + pub link: &'a String, } pub struct TagArticles<'a> { tag: &'a String, - article_links: Vec> + article_links: Vec>, } impl TagArticles<'_> { - pub fn new<'a>(tag: &'a String, article_links: &'a Vec<(FrontMatter, String)>) -> TagArticles<'a> { + pub fn new<'a>( + tag: &'a String, + article_links: &'a Vec<(FrontMatter, String)>, + ) -> TagArticles<'a> { let mut qual_article_links = Vec::new(); for (frontmatter, link) in article_links { qual_article_links.push(ArticleLink { frontmatter, link }); } - TagArticles { tag, article_links: qual_article_links } + TagArticles { + tag, + article_links: qual_article_links, + } } } @@ -49,6 +55,10 @@ impl TemplateRenderer for TagArticles<'_> { let mut terra_context = tera::Context::new(); terra_context.insert("tag", &self.tag); terra_context.insert("article_links", &self.article_links); - tera.render("tag-articles.html", &terra_context).context(format!("Failed to render tag articles page for tag: {}", &self.tag)) + tera.render("tag-articles.html", &terra_context) + .context(format!( + "Failed to render tag articles page for tag: {}", + &self.tag + )) } } diff --git a/src/tree_sitter_adapter.rs b/src/tree_sitter_adapter.rs index 4212e6b..b36ad65 100644 --- a/src/tree_sitter_adapter.rs +++ b/src/tree_sitter_adapter.rs @@ -12,7 +12,6 @@ /// https://andrewtbiehl.com/blog/jekyll-tree-sitter is what sent me down this horrid path along /// with some of his code in his kramdown syntax module. I did *significantly* speed this code up /// though, as in several magnitudes for my purposes. - use std::{ collections::HashMap, convert, @@ -92,7 +91,9 @@ impl TreesitterSyntaxAdapter { let (language, lang_config) = Self::get_language_config(&loader, code_lang)?; let highlight_config = Self::get_highlight_configuration(language, lang_config, code_lang)?; let highlights = - highlighter.highlight(&highlight_config, code.as_bytes(), None, |lang| loader.highlight_config_for_injection_string(lang))?; + highlighter.highlight(&highlight_config, code.as_bytes(), None, |lang| { + loader.highlight_config_for_injection_string(lang) + })?; // loader.configure_highlights(&highlight_config.names().to_vec()); Ok(highlights) @@ -106,7 +107,6 @@ impl TreesitterSyntaxAdapter { } impl SyntaxHighlighterAdapter for TreesitterSyntaxAdapter { - fn write_highlighted( &self, output: &mut dyn Write,