Compare commits
No commits in common. "64954a3d5cff057ba9cccc5590827d22fd42e2fb" and "9046ac910d1c729a67583dccde496be27b0a22d6" have entirely different histories.
64954a3d5c
...
9046ac910d
4 changed files with 31 additions and 10 deletions
|
@ -23,13 +23,27 @@ 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(hash);
|
||||
self.hash = Some(h.finish());
|
||||
}
|
||||
// safety: please.
|
||||
unsafe { self.inner.as_ref().unwrap_unchecked().clone() }
|
||||
|
|
|
@ -335,11 +335,7 @@ 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,
|
||||
config.cache.compression_level,
|
||||
)?
|
||||
.auto_finish(),
|
||||
&mut zstd::stream::write::Encoder::new(cache_file, 3)?.auto_finish(),
|
||||
&serialized,
|
||||
)
|
||||
})
|
||||
|
|
|
@ -32,7 +32,7 @@ fn build_syntect(config: &RenderConfig) -> Arc<SyntectAdapter> {
|
|||
Arc::new(builder.build())
|
||||
}
|
||||
|
||||
pub fn render(markdown: &str, config: &RenderConfig) -> String {
|
||||
pub fn render(markdown: &str, config: &RenderConfig, front_matter: bool) -> String {
|
||||
let mut options = ComrakOptions::default();
|
||||
options.extension.table = true;
|
||||
options.extension.autolink = true;
|
||||
|
@ -41,6 +41,9 @@ pub fn render(markdown: &str, config: &RenderConfig) -> String {
|
|||
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);
|
||||
|
|
|
@ -121,7 +121,7 @@ impl PostManager {
|
|||
let parsing = parsing_start.elapsed();
|
||||
|
||||
let before_render = Instant::now();
|
||||
let rendered_markdown = render(body, &self.config);
|
||||
let rendered_markdown = render(body, &self.config, false);
|
||||
let post = Post {
|
||||
meta: &metadata,
|
||||
rendered_markdown,
|
||||
|
@ -148,10 +148,13 @@ impl PostManager {
|
|||
Ok((metadata, post, (parsing, rendering)))
|
||||
}
|
||||
|
||||
pub async fn list_posts(&self) -> Result<Vec<PostMetadata>, PostError> {
|
||||
async fn list_posts_recursive(
|
||||
&self,
|
||||
dir: impl AsRef<Path>,
|
||||
) -> Result<Vec<PostMetadata>, PostError> {
|
||||
let mut posts = Vec::new();
|
||||
|
||||
let mut read_dir = fs::read_dir(&self.dir).await?;
|
||||
let mut read_dir = fs::read_dir(dir).await?;
|
||||
while let Some(entry) = read_dir.next_entry().await? {
|
||||
let path = entry.path();
|
||||
let stat = fs::metadata(&path).await?;
|
||||
|
@ -182,6 +185,11 @@ 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,
|
||||
|
|
Loading…
Reference in a new issue