Skip to content

Commit c6f659c

Browse files
committed
Reduce dependencies
1 parent e596b57 commit c6f659c

File tree

8 files changed

+155
-303
lines changed

8 files changed

+155
-303
lines changed

Cargo.lock

Lines changed: 117 additions & 263 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,34 @@ ramhorns = { git = "https://github.com/grego/ramhorns", branch = "shorthand" }
1616
arrayvec = { version = "0.7", features = ["serde"] }
1717
beef = { version = "0.5", features = ["impl_serde"]}
1818
serde = { version = "^1.0.126", features = ["derive"] }
19-
chrono = { version = "^0.4.19", features = ["clock", "serde"], default_features = false }
19+
chrono = { version = "^0.4.19", features = ["std", "serde"], default_features = false }
2020
fnv = "1.0"
21-
ahash = "0.7"
22-
hashbrown = { version = "0.11.2", features = ["inline-more", "serde"], default_features = false }
23-
parking_lot = "0.11.1"
21+
hashbrown = { version = "0.12.1", features = ["inline-more", "serde"], default_features = false }
2422
serde-cmd = "0.1.3"
25-
pulldown-cmark = "0.9"
23+
pulldown-cmark = { version = "0.9", default_features = false }
2624
cmark-syntax = "0.3"
2725

2826
# Cargo doesn't support binary-only dependencies yet.
29-
toml = { version = "0.5.8", optional = true }
30-
rayon = { version = "1.5.1", optional = true }
31-
structopt = { version = "0.3.22", optional = true }
32-
thiserror = { version = "1.0.26", optional = true }
27+
toml = { version = "0.5.9", optional = true }
28+
rayon = { version = "1.5.3", optional = true }
29+
clap = { version = "3.1.18", optional = true, default_features = false, features = ["std"] }
30+
clap_derive = { version = "3.1.18", optional = true }
31+
thiserror = { version = "1.0.31", optional = true }
3332
serde_json = { version = "1", optional = true }
3433

3534
[features]
36-
bin = ["toml", "rayon", "structopt", "thiserror", "serde_json", "hashbrown/rayon"]
35+
bin = ["toml", "rayon", "clap", "clap_derive", "thiserror", "serde_json", "hashbrown/rayon"]
3736
mathml = ["cmark-syntax/latex2mathml"]
3837
default = ["bin", "mathml"]
3938

4039
[profile.release]
4140
lto = true
41+
opt-level = 3
42+
strip = "debuginfo"
43+
codegen-units = 1
4244

4345
[profile.bench]
4446
lto = true
4547

4648
[patch.crates-io]
4749
ramhorns-derive = { git = "https://github.com/grego/ramhorns", branch = "shorthand" }
48-

benches/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const RENDERED_BYTES: u64 =
77
"Hello, Ramhorns!This is a really simple test of the rendering!<title></title><h1></h1><div></div>".len() as u64;
88

99
#[bench]
10-
fn ahash_hashmap(b: &mut Bencher) {
10+
fn fnv_hashmap(b: &mut Bencher) {
1111
let tpl = ramhorns::Template::new(SOURCE).unwrap();
1212

13-
let mut map: std::collections::HashMap<_, _, ahash::RandomState> = Default::default();
13+
let mut map: std::collections::HashMap<_, _, fnv::FnvBuildHasher> = Default::default();
1414
map.insert("title", "Hello, Ramhorns!");
1515
map.insert("body", "This is a really simple test of the rendering!");
1616

examples/transform_plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
66
std::io::stdin().read_to_end(&mut source)?;
77
// When deserializing from a slice, zero-copy deserialiation can be used
88
let mut pages: Vec<Page> = serde_json::from_slice(&source)?;
9-
9+
1010
for page in &mut pages {
1111
if page.content.find("dog").is_some() {
1212
page.summary = "WARNING! CONTAINS DOGS!".into();

src/main.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// along with Blades. If not, see <http://www.gnu.org/licenses/>
99
use blades::*;
1010

11-
use chrono::offset::Local;
11+
use clap::Parser as ClapParser;
1212
use ramhorns::{Content, Template};
1313
use rayon::prelude::*;
1414
use std::env::var;
@@ -17,23 +17,22 @@ use std::fs::{create_dir_all, read_to_string, write};
1717
use std::io::{stdin, stdout, BufRead, BufReader, Lines, Write};
1818
use std::path::Path;
1919
use std::process::{Command, Output, Stdio};
20-
use std::time::Instant;
21-
use structopt::StructOpt;
20+
use std::time::{Instant, SystemTime};
2221
use thiserror::Error;
2322

2423
static CONFIG_FILE: &str = "Blades.toml";
2524

26-
#[derive(StructOpt)]
25+
#[derive(clap_derive::Parser)]
2726
/// Blazing fast Dead simple Static site generator
2827
struct Opt {
2928
/// File to read the site config from
30-
#[structopt(short, long, default_value = CONFIG_FILE)]
29+
#[clap(short, long, default_value = CONFIG_FILE)]
3130
config: String,
32-
#[structopt(subcommand)]
31+
#[clap(subcommand)]
3332
cmd: Option<Cmd>,
3433
}
3534

36-
#[derive(PartialEq, StructOpt)]
35+
#[derive(PartialEq, clap_derive::Subcommand)]
3736
enum Cmd {
3837
/// Initialise the site in the current directory, creating the basic files and folders
3938
Init,
@@ -228,7 +227,9 @@ fn new_page(config: &Config) -> Result<(), Error> {
228227
"Path (relative to the content directory):",
229228
)?);
230229
create_dir_all(&path)?;
231-
let date = Local::now().format("%Y-%m-%d").to_string();
230+
231+
let date: chrono::DateTime<chrono::Utc> = SystemTime::now().into();
232+
let date = date.format("%Y-%m-%d").to_string();
232233
path.push(format!("{}-{}.toml", &date, &slug));
233234

234235
if path.exists() {
@@ -374,7 +375,7 @@ fn build(config: &Config) -> Result<(), Error> {
374375
taxonomy.render_key((n, l), config, &taxonomies, &pages, &templates, &rendered)
375376
})
376377
})?;
377-
render_meta(&pages, &taxonomies, config, &rendered).map_err(Into::into)
378+
render_meta(&pages, &taxonomies, config).map_err(Into::into)
378379
},
379380
);
380381
res_l?;
@@ -401,7 +402,7 @@ fn build(config: &Config) -> Result<(), Error> {
401402
}
402403

403404
fn main() {
404-
let opt = Opt::from_args();
405+
let opt: Opt = ClapParser::parse();
405406
let start = Instant::now();
406407

407408
let config_file = match std::fs::read_to_string(&opt.config) {

src/sources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<P: Parser> Sources<P> {
139139
let read = File::open(&path)?.read_to_end(&mut self.data)?;
140140
let mid = start + read;
141141
let path = path.to_string_lossy();
142-
let ext_start = path.rfind('.').unwrap_or_else(|| path.len());
142+
let ext_start = path.rfind('.').unwrap_or(path.len());
143143
self.data.extend_from_slice(path[..ext_start].as_ref());
144144
let end = self.data.len();
145145
self.sources

src/tasks.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ where
4545
{
4646
let path = path.into();
4747
template.render_to_file(&path, content)?;
48-
if let Some(path) = rendered.lock().replace(path) {
48+
if let Some(path) = rendered.lock().unwrap().replace(path) {
4949
println!("Warning: more paths render to {}", path.to_string_lossy());
5050
}
5151
Ok(())
@@ -61,14 +61,10 @@ struct Meta<'p, 'r>(
6161

6262
impl<'p> Meta<'p, '_> {
6363
#[inline]
64-
fn render(
65-
&self,
66-
name: &str,
67-
template: &str,
68-
path: &Path,
69-
rendered: &MutSet,
70-
) -> Result<(), ramhorns::Error> {
71-
render(&Template::new(template)?, path.join(name), self, rendered)
64+
fn render(&self, name: &str, template: &str, path: &Path) -> Result<(), ramhorns::Error> {
65+
Template::new(template)?
66+
.render_to_file(path.join(name), self)
67+
.map_err(Into::into)
7268
}
7369
}
7470

@@ -77,23 +73,22 @@ pub fn render_meta<'p>(
7773
pages: &[Page<'p>],
7874
taxons: &Classification<'p, '_>,
7975
config: &Config<'p>,
80-
rendered: &MutSet,
8176
) -> Result<(), ramhorns::Error> {
8277
let pages = PageList::new(pages, 0..pages.len(), 0, &config.url);
8378
let meta = Meta(DateTime::now(), pages, TaxonList(taxons), config);
8479
let path = Path::new(config.output_dir.as_ref());
8580

8681
if config.sitemap {
8782
let sitemap = include_str!("templates/sitemap.xml");
88-
meta.render("sitemap.xml", sitemap, path, rendered)?;
83+
meta.render("sitemap.xml", sitemap, path)?;
8984
}
9085
if config.rss {
9186
let rss = include_str!("templates/rss.xml");
92-
meta.render("rss.xml", rss, path, rendered)?;
87+
meta.render("rss.xml", rss, path)?;
9388
}
9489
if config.atom {
9590
let atom = include_str!("templates/atom.xml");
96-
meta.render("atom.xml", atom, path, rendered)?;
91+
meta.render("atom.xml", atom, path)?;
9792
}
9893
Ok(())
9994
}
@@ -146,7 +141,7 @@ pub fn colocate_assets(config: &Config) -> Result<(), io::Error> {
146141
/// Delete all the pages that were present in the previous render, but not the current one.
147142
/// Then, write all the paths that were rendered to the file `filelist`
148143
pub fn cleanup(rendered: MutSet, filelist: &str) -> Result<(), io::Error> {
149-
let rendered = rendered.into_inner();
144+
let rendered = rendered.into_inner().unwrap();
150145
if let Ok(f) = File::open(filelist) {
151146
BufReader::new(f).lines().try_for_each(|filename| {
152147
let filename = filename?;

src/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ use std::fmt;
1919
use std::hash::Hash;
2020
use std::ops::{Deref, DerefMut};
2121
use std::path::{is_separator, PathBuf};
22+
use std::sync::Mutex;
2223
use std::time::SystemTime;
2324

2425
/// A set of all rendered paths. Behind a mutex, so it can be written from multiple threads.
25-
pub type MutSet<T = PathBuf> = parking_lot::Mutex<HashSet<T, ahash::RandomState>>;
26+
pub type MutSet<T = PathBuf> = Mutex<HashSet<T, fnv::FnvBuildHasher>>;
2627

2728
/// A hash map wrapper that can render fields directly by the hash.
2829
#[derive(Clone, serde::Deserialize, serde::Serialize)]

0 commit comments

Comments
 (0)