From 5930df6609b279163f935999fb66d77f47834d55 Mon Sep 17 00:00:00 2001 From: slonkazoid Date: Sun, 21 Apr 2024 00:23:43 +0300 Subject: [PATCH] remove redundant code --- src/hash_arc_store.rs | 16 +--------------- src/markdown_render.rs | 5 +---- src/post/mod.rs | 14 +++----------- 3 files changed, 5 insertions(+), 30 deletions(-) diff --git a/src/hash_arc_store.rs b/src/hash_arc_store.rs index e2398a2..90b35b4 100644 --- a/src/hash_arc_store.rs +++ b/src/hash_arc_store.rs @@ -23,27 +23,13 @@ where } } - /*pub fn get(&self, key: &Lookup) -> Option> { - self.hash.and_then(|hash| { - let mut h = DefaultHasher::new(); - key.hash(&mut h); - if hash == h.finish() { - self.inner.clone() - } else { - None - } - }) - }*/ - pub fn get_or_init(&mut self, key: &Lookup, init: impl Fn(&Lookup) -> Arc) -> Arc { let mut h = DefaultHasher::new(); key.hash(&mut h); let hash = h.finish(); if !self.hash.is_some_and(|inner_hash| inner_hash == hash) { - let mut h = DefaultHasher::new(); - key.hash(&mut h); self.inner = Some(init(key)); - self.hash = Some(h.finish()); + self.hash = Some(hash); } // safety: please. unsafe { self.inner.as_ref().unwrap_unchecked().clone() } diff --git a/src/markdown_render.rs b/src/markdown_render.rs index e128fc7..7153b3c 100644 --- a/src/markdown_render.rs +++ b/src/markdown_render.rs @@ -32,7 +32,7 @@ fn build_syntect(config: &RenderConfig) -> Arc { Arc::new(builder.build()) } -pub fn render(markdown: &str, config: &RenderConfig, front_matter: bool) -> String { +pub fn render(markdown: &str, config: &RenderConfig) -> String { let mut options = ComrakOptions::default(); options.extension.table = true; options.extension.autolink = true; @@ -41,9 +41,6 @@ pub fn render(markdown: &str, config: &RenderConfig, front_matter: bool) -> Stri options.extension.strikethrough = true; options.extension.multiline_block_quotes = true; options.extension.header_ids = Some(String::new()); - if front_matter { - options.extension.front_matter_delimiter = Some(String::from("---")); - }; let mut render_plugins = RenderPlugins::default(); let syntect = syntect_adapter(config); diff --git a/src/post/mod.rs b/src/post/mod.rs index f61fc68..a08c428 100644 --- a/src/post/mod.rs +++ b/src/post/mod.rs @@ -121,7 +121,7 @@ impl PostManager { let parsing = parsing_start.elapsed(); let before_render = Instant::now(); - let rendered_markdown = render(body, &self.config, false); + let rendered_markdown = render(body, &self.config); let post = Post { meta: &metadata, rendered_markdown, @@ -148,13 +148,10 @@ impl PostManager { Ok((metadata, post, (parsing, rendering))) } - async fn list_posts_recursive( - &self, - dir: impl AsRef, - ) -> Result, PostError> { + pub async fn list_posts(&self) -> Result, PostError> { let mut posts = Vec::new(); - let mut read_dir = fs::read_dir(dir).await?; + let mut read_dir = fs::read_dir(&self.dir).await?; while let Some(entry) = read_dir.next_entry().await? { let path = entry.path(); let stat = fs::metadata(&path).await?; @@ -185,11 +182,6 @@ impl PostManager { Ok(posts) } - #[allow(unused)] - pub async fn list_posts(&self) -> Result, PostError> { - self.list_posts_recursive(&self.dir).await - } - // third entry in the tuple is whether it got rendered and if so, how long did it take pub async fn get_post( &self,