style: format with rustfmt
This commit is contained in:
parent
c8b1e0b333
commit
b8ffc4d365
13
src/main.rs
13
src/main.rs
@ -8,7 +8,7 @@ use blog::{
|
|||||||
TemplateRenderer,
|
TemplateRenderer,
|
||||||
};
|
};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
use std::{collections::HashMap, fs::DirEntry, path::PathBuf};
|
||||||
use tera::Tera;
|
use tera::Tera;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
@ -113,10 +113,13 @@ fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
for static_page in static_pages {
|
for static_page in static_pages {
|
||||||
println!("Rendering Static Page: {}", &static_page);
|
println!("Rendering Static Page: {}", &static_page);
|
||||||
let rendered_static_page = tera.render(&format!("static/{}", &static_page), &static_context)?;
|
let rendered_static_page =
|
||||||
write_file(&out_path.join(&static_page), rendered_static_page.as_bytes())?;
|
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);
|
println!("Finished Rendering Static Page: {}", &static_page);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let base_asset_dir = PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/"));
|
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:?}"))
|
std::fs::write(file_path, contents).context(format!("Failed to write to {file_path:?}"))
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ use super::{iter_nodes, MDComrakSettings};
|
|||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct Article {
|
pub struct Article {
|
||||||
pub html_content: String,
|
pub html_content: String,
|
||||||
pub frontmatter: FrontMatter
|
pub frontmatter: FrontMatter,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[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_last_updated", &self.frontmatter.updated);
|
||||||
tera_context.insert("article_tags", &self.frontmatter.tags);
|
tera_context.insert("article_tags", &self.frontmatter.tags);
|
||||||
tera_context.insert("article_content", &self.html_content);
|
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
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,24 @@
|
|||||||
use std::io::{Cursor, Write};
|
use comrak::{
|
||||||
use comrak::{nodes::{AstNode, Sourcepos}, ComrakOptions, ComrakPlugins, plugins::syntect::{SyntectAdapter, SyntectAdapterBuilder}, adapters::{HeadingAdapter, HeadingMeta}, Anchorizer};
|
adapters::{HeadingAdapter, HeadingMeta},
|
||||||
|
nodes::{AstNode, Sourcepos},
|
||||||
|
plugins::syntect::{SyntectAdapter, SyntectAdapterBuilder},
|
||||||
|
Anchorizer, ComrakOptions, ComrakPlugins,
|
||||||
|
};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use std::io::{Cursor, Write};
|
||||||
use syntect::highlighting::ThemeSet;
|
use syntect::highlighting::ThemeSet;
|
||||||
|
|
||||||
pub mod article;
|
pub mod article;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref SYNTECT_ADAPTER: SyntectAdapter =
|
pub static ref SYNTECT_ADAPTER: SyntectAdapter = MDComrakSettings::load_theme(
|
||||||
MDComrakSettings::load_theme("kanagawa", &mut Cursor::new(include_bytes!(concat!(
|
"kanagawa",
|
||||||
|
&mut Cursor::new(include_bytes!(concat!(
|
||||||
env!("CARGO_MANIFEST_DIR"),
|
env!("CARGO_MANIFEST_DIR"),
|
||||||
"/assets/Kanagawa.tmTheme"
|
"/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)
|
pub fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &mut F)
|
||||||
@ -27,7 +34,7 @@ where
|
|||||||
struct HeaderLinkAdapter;
|
struct HeaderLinkAdapter;
|
||||||
|
|
||||||
impl HeadingAdapter for HeaderLinkAdapter {
|
impl HeadingAdapter for HeaderLinkAdapter {
|
||||||
fn enter(
|
fn enter(
|
||||||
&self,
|
&self,
|
||||||
output: &mut dyn Write,
|
output: &mut dyn Write,
|
||||||
heading: &HeadingMeta,
|
heading: &HeadingMeta,
|
||||||
@ -87,4 +94,4 @@ impl MDComrakSettings<'_> {
|
|||||||
|
|
||||||
Ok(adapter)
|
Ok(adapter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,4 +8,4 @@ pub mod tags;
|
|||||||
pub struct ArticleLink<'a> {
|
pub struct ArticleLink<'a> {
|
||||||
frontmatter: &'a FrontMatter,
|
frontmatter: &'a FrontMatter,
|
||||||
link: &'a String,
|
link: &'a String,
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
use crate::{markdown::article::FrontMatter, TemplateRenderer};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use crate::{TemplateRenderer, markdown::article::FrontMatter};
|
|
||||||
|
|
||||||
pub struct Tags<'a> {
|
pub struct Tags<'a> {
|
||||||
tags: &'a Vec<&'a String>,
|
tags: &'a Vec<&'a String>,
|
||||||
@ -26,21 +26,27 @@ impl TemplateRenderer for Tags<'_> {
|
|||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct ArticleLink<'a> {
|
pub struct ArticleLink<'a> {
|
||||||
pub frontmatter: &'a FrontMatter,
|
pub frontmatter: &'a FrontMatter,
|
||||||
pub link: &'a String
|
pub link: &'a String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TagArticles<'a> {
|
pub struct TagArticles<'a> {
|
||||||
tag: &'a String,
|
tag: &'a String,
|
||||||
article_links: Vec<ArticleLink<'a>>
|
article_links: Vec<ArticleLink<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TagArticles<'_> {
|
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();
|
let mut qual_article_links = Vec::new();
|
||||||
for (frontmatter, link) in article_links {
|
for (frontmatter, link) in article_links {
|
||||||
qual_article_links.push(ArticleLink { frontmatter, link });
|
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();
|
let mut terra_context = tera::Context::new();
|
||||||
terra_context.insert("tag", &self.tag);
|
terra_context.insert("tag", &self.tag);
|
||||||
terra_context.insert("article_links", &self.article_links);
|
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
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
/// https://andrewtbiehl.com/blog/jekyll-tree-sitter is what sent me down this horrid path along
|
/// 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
|
/// 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.
|
/// though, as in several magnitudes for my purposes.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
convert,
|
convert,
|
||||||
@ -92,7 +91,9 @@ impl TreesitterSyntaxAdapter {
|
|||||||
let (language, lang_config) = Self::get_language_config(&loader, code_lang)?;
|
let (language, lang_config) = Self::get_language_config(&loader, code_lang)?;
|
||||||
let highlight_config = Self::get_highlight_configuration(language, lang_config, code_lang)?;
|
let highlight_config = Self::get_highlight_configuration(language, lang_config, code_lang)?;
|
||||||
let highlights =
|
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());
|
// loader.configure_highlights(&highlight_config.names().to_vec());
|
||||||
|
|
||||||
Ok(highlights)
|
Ok(highlights)
|
||||||
@ -106,7 +107,6 @@ impl TreesitterSyntaxAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SyntaxHighlighterAdapter for TreesitterSyntaxAdapter {
|
impl SyntaxHighlighterAdapter for TreesitterSyntaxAdapter {
|
||||||
|
|
||||||
fn write_highlighted(
|
fn write_highlighted(
|
||||||
&self,
|
&self,
|
||||||
output: &mut dyn Write,
|
output: &mut dyn Write,
|
||||||
|
Loading…
Reference in New Issue
Block a user