style: format with rustfmt

This commit is contained in:
Price Hiller 2023-09-19 11:24:22 -05:00
parent c8b1e0b333
commit b8ffc4d365
No known key found for this signature in database
6 changed files with 48 additions and 25 deletions

View File

@ -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:?}"))
}
}

View File

@ -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
))
}
}

View File

@ -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)
}
}
}

View File

@ -8,4 +8,4 @@ pub mod tags;
pub struct ArticleLink<'a> {
frontmatter: &'a FrontMatter,
link: &'a String,
}
}

View File

@ -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<ArticleLink<'a>>
article_links: Vec<ArticleLink<'a>>,
}
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
))
}
}

View File

@ -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,