forked from slonk/bingus-blog
remove redundant code
This commit is contained in:
parent
9046ac910d
commit
5930df6609
3 changed files with 5 additions and 30 deletions
|
@ -23,27 +23,13 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*pub fn get(&self, key: &Lookup) -> Option<Arc<T>> {
|
|
||||||
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<T>) -> Arc<T> {
|
pub fn get_or_init(&mut self, key: &Lookup, init: impl Fn(&Lookup) -> Arc<T>) -> Arc<T> {
|
||||||
let mut h = DefaultHasher::new();
|
let mut h = DefaultHasher::new();
|
||||||
key.hash(&mut h);
|
key.hash(&mut h);
|
||||||
let hash = h.finish();
|
let hash = h.finish();
|
||||||
if !self.hash.is_some_and(|inner_hash| inner_hash == hash) {
|
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.inner = Some(init(key));
|
||||||
self.hash = Some(h.finish());
|
self.hash = Some(hash);
|
||||||
}
|
}
|
||||||
// safety: please.
|
// safety: please.
|
||||||
unsafe { self.inner.as_ref().unwrap_unchecked().clone() }
|
unsafe { self.inner.as_ref().unwrap_unchecked().clone() }
|
||||||
|
|
|
@ -32,7 +32,7 @@ fn build_syntect(config: &RenderConfig) -> Arc<SyntectAdapter> {
|
||||||
Arc::new(builder.build())
|
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();
|
let mut options = ComrakOptions::default();
|
||||||
options.extension.table = true;
|
options.extension.table = true;
|
||||||
options.extension.autolink = 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.strikethrough = true;
|
||||||
options.extension.multiline_block_quotes = true;
|
options.extension.multiline_block_quotes = true;
|
||||||
options.extension.header_ids = Some(String::new());
|
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 mut render_plugins = RenderPlugins::default();
|
||||||
let syntect = syntect_adapter(config);
|
let syntect = syntect_adapter(config);
|
||||||
|
|
|
@ -121,7 +121,7 @@ impl PostManager {
|
||||||
let parsing = parsing_start.elapsed();
|
let parsing = parsing_start.elapsed();
|
||||||
|
|
||||||
let before_render = Instant::now();
|
let before_render = Instant::now();
|
||||||
let rendered_markdown = render(body, &self.config, false);
|
let rendered_markdown = render(body, &self.config);
|
||||||
let post = Post {
|
let post = Post {
|
||||||
meta: &metadata,
|
meta: &metadata,
|
||||||
rendered_markdown,
|
rendered_markdown,
|
||||||
|
@ -148,13 +148,10 @@ impl PostManager {
|
||||||
Ok((metadata, post, (parsing, rendering)))
|
Ok((metadata, post, (parsing, rendering)))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn list_posts_recursive(
|
pub async fn list_posts(&self) -> Result<Vec<PostMetadata>, PostError> {
|
||||||
&self,
|
|
||||||
dir: impl AsRef<Path>,
|
|
||||||
) -> Result<Vec<PostMetadata>, PostError> {
|
|
||||||
let mut posts = Vec::new();
|
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? {
|
while let Some(entry) = read_dir.next_entry().await? {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
let stat = fs::metadata(&path).await?;
|
let stat = fs::metadata(&path).await?;
|
||||||
|
@ -185,11 +182,6 @@ impl PostManager {
|
||||||
Ok(posts)
|
Ok(posts)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
pub async fn list_posts(&self) -> Result<Vec<PostMetadata>, 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
|
// third entry in the tuple is whether it got rendered and if so, how long did it take
|
||||||
pub async fn get_post(
|
pub async fn get_post(
|
||||||
&self,
|
&self,
|
||||||
|
|
Loading…
Reference in a new issue