Skip to content

Commit

Permalink
Use rayon to parallelize the blog post rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Oct 24, 2023
1 parent d6ea45c commit ff12112
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
75 changes: 75 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ serde_derive = "1.0"
serde_yaml = "0.8"
serde_json = "1.0"
comrak = "0.13"
rayon = "1.8.0"
regex = "1.3"
sass-rs = "0.2"
chrono = "0.4"
Expand Down
9 changes: 4 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::error::Error;
use std::fs::{self, File};
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use rayon::prelude::*;

struct Generator<'a> {
handlebars: Handlebars<'a>,
Expand Down Expand Up @@ -126,11 +127,9 @@ impl<'a> Generator<'a> {
self.render_feed(blog)?;
self.render_releases_feed(blog)?;

for (i, post) in blog.posts().iter().enumerate() {
let path = self.render_post(blog, post)?;
if i == 0 {
println!("└─ Latest post: {}\n", self.file_url(&path));
}
let paths = blog.posts().par_iter().map(|post| self.render_post(blog, post)).collect::<Result<Vec<_>, _>>()?;
if let Some(path) = paths.first() {
println!("└─ Latest post: {}\n", self.file_url(path));
}

Ok(())
Expand Down

0 comments on commit ff12112

Please sign in to comment.