Compare commits

...

2 commits

Author SHA1 Message Date
64954a3d5c
respect compession level 2024-04-21 00:46:28 +03:00
5930df6609
remove redundant code 2024-04-21 00:38:30 +03:00
4 changed files with 10 additions and 31 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

@ -335,7 +335,11 @@ async fn main() -> eyre::Result<()> {
let cache_file = cache_file.into_std().await;
tokio::task::spawn_blocking(move || {
std::io::Write::write_all(
&mut zstd::stream::write::Encoder::new(cache_file, 3)?.auto_finish(),
&mut zstd::stream::write::Encoder::new(
cache_file,
config.cache.compression_level,
)?
.auto_finish(),
&serialized,
)
})

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,