remove redundant code

This commit is contained in:
slonkazoid 2024-04-21 00:23:43 +03:00
parent 9046ac910d
commit 5930df6609
Signed by: slonk
SSH key fingerprint: SHA256:tbZfJX4IOvZ0LGWOWu5Ijo8jfMPi78TU7x1VoEeCIjM
3 changed files with 5 additions and 30 deletions

View file

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

View file

@ -32,7 +32,7 @@ fn build_syntect(config: &RenderConfig) -> Arc<SyntectAdapter> {
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);

View file

@ -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<Path>,
) -> Result<Vec<PostMetadata>, PostError> {
pub async fn list_posts(&self) -> Result<Vec<PostMetadata>, 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<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
pub async fn get_post(
&self,