Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libs subcrate #1747

Merged
merged 4 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
341 changes: 211 additions & 130 deletions Cargo.lock

Large diffs are not rendered by default.

29 changes: 7 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,16 @@ name = "zola"
[dependencies]
atty = "0.2.11"
clap = { version = "3", features = ["derive"] }
chrono = "0.4"
lazy_static = "1.1"
termcolor = "1.0.4"
# Used in init to ensure the url given as base_url is a valid one
url = "2"
# Below is for the serve cmd
hyper = { version = "0.14.1", default-features = false, features = ["runtime", "server", "http2", "http1"] }
tokio = { version = "1.0.1", default-features = false, features = ["rt", "fs", "time"] }
percent-encoding = "2"
notify = "4"
ws = "0.9"
ctrlc = "3"
open = "2"
globset = "0.4"
relative-path = "1"
pathdiff = "0.2"
serde_json = "1.0"
# For mimetype detection in serve mode
mime_guess = "2.0"

Expand All @@ -47,29 +40,21 @@ errors = { path = "components/errors" }
front_matter = { path = "components/front_matter" }
utils = { path = "components/utils" }
search = { path = "components/search" }
libs = { path = "components/libs" }


[dev-dependencies]
same-file = "1"

[features]
default = ["rust-tls"]
rust-tls = ["site/rust-tls"]
native-tls = ["site/native-tls"]
rust-tls = ["libs/rust-tls"]
native-tls = ["libs/native-tls"]
indexing-zh = ["libs/indexing-zh"]
indexing-ja = ["libs/indexing-ja"]

[workspace]
members = [
"components/config",
"components/errors",
"components/front_matter",
"components/rendering",
"components/site",
"components/templates",
"components/utils",
"components/search",
"components/imageproc",
"components/link_checker",
"components/library",
]
members = ["components/*"]

[profile.release]
lto = true
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ stages:
rustup_toolchain: stable
linux-pinned:
imageName: 'ubuntu-20.04'
rustup_toolchain: 1.54.0
rustup_toolchain: 1.56.0
pool:
vmImage: $(imageName)
steps:
Expand Down
13 changes: 3 additions & 10 deletions components/config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
[package]
name = "config"
version = "0.1.0"
authors = ["Vincent Prouillet <[email protected]>"]
edition = "2018"
edition = "2021"
include = ["src/**/*"]

[dependencies]
toml = "0.5"
serde = "1"
serde_derive = "1"
chrono = "0.4"
globset = "0.4"
lazy_static = "1"
syntect = "4"
unic-langid = "0.9"
serde = {version = "1.0", features = ["derive"] }

errors = { path = "../errors" }
utils = { path = "../utils" }
libs = { path = "../libs" }
6 changes: 3 additions & 3 deletions components/config/examples/generate_sublime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
//! Although it is a valid example for serializing syntaxes, you probably won't need
//! to do this yourself unless you want to cache your own compiled grammars.
use libs::syntect::dumps::*;
use libs::syntect::highlighting::ThemeSet;
use libs::syntect::parsing::SyntaxSetBuilder;
use std::collections::HashMap;
use std::collections::HashSet;
use std::env;
use std::iter::FromIterator;
use std::path::Path;
use syntect::dumps::*;
use syntect::highlighting::ThemeSet;
use syntect::parsing::SyntaxSetBuilder;

fn usage_and_exit() -> ! {
println!("USAGE: cargo run --example generate_sublime synpack source-dir newlines.packdump nonewlines.packdump\n
Expand Down
4 changes: 2 additions & 2 deletions components/config/src/config/languages.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::collections::HashMap;

use errors::{bail, Result};
use serde_derive::{Deserialize, Serialize};
use unic_langid::LanguageIdentifier;
use libs::unic_langid::LanguageIdentifier;
use serde::{Deserialize, Serialize};

use crate::config::search;
use crate::config::taxonomies;
Expand Down
3 changes: 1 addition & 2 deletions components/config/src/config/link_checker.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde_derive::{Deserialize, Serialize};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
Expand All @@ -8,4 +8,3 @@ pub struct LinkChecker {
/// Skip anchor checking for these URL prefixes
pub skip_anchor_prefixes: Vec<String>,
}

4 changes: 2 additions & 2 deletions components/config/src/config/markup.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::{path::Path, sync::Arc};

use serde_derive::{Deserialize, Serialize};
use syntect::{
use libs::syntect::{
highlighting::{Theme, ThemeSet},
html::css_for_theme_with_class_style,
parsing::{SyntaxSet, SyntaxSetBuilder},
};
use serde::{Deserialize, Serialize};

use errors::{bail, Result};

Expand Down
8 changes: 4 additions & 4 deletions components/config/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ pub mod taxonomies;
use std::collections::HashMap;
use std::path::{Path, PathBuf};

use globset::{Glob, GlobSet, GlobSetBuilder};
use serde_derive::{Deserialize, Serialize};
use toml::Value as Toml;
use libs::globset::{Glob, GlobSet, GlobSetBuilder};
use libs::toml::Value as Toml;
use serde::{Deserialize, Serialize};

use crate::theme::Theme;
use errors::{bail, Error, Result};
Expand Down Expand Up @@ -109,7 +109,7 @@ impl Config {
/// Parses a string containing TOML to our Config struct
/// Any extra parameter will end up in the extra field
pub fn parse(content: &str) -> Result<Config> {
let mut config: Config = match toml::from_str(content) {
let mut config: Config = match libs::toml::from_str(content) {
Ok(c) => c,
Err(e) => bail!(e),
};
Expand Down
2 changes: 1 addition & 1 deletion components/config/src/config/search.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde_derive::{Deserialize, Serialize};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
Expand Down
2 changes: 1 addition & 1 deletion components/config/src/config/slugify.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde_derive::{Deserialize, Serialize};
use serde::{Deserialize, Serialize};

use utils::slugs::SlugifyStrategy;

Expand Down
2 changes: 1 addition & 1 deletion components/config/src/config/taxonomies.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde_derive::{Deserialize, Serialize};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
Expand Down
24 changes: 10 additions & 14 deletions components/config/src/highlighting.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
use lazy_static::lazy_static;
use syntect::dumps::from_binary;
use syntect::highlighting::{Theme, ThemeSet};
use syntect::html::ClassStyle;
use syntect::parsing::{SyntaxReference, SyntaxSet};
use libs::syntect::dumps::from_binary;
use libs::syntect::highlighting::{Theme, ThemeSet};
use libs::syntect::html::ClassStyle;
use libs::syntect::parsing::{SyntaxReference, SyntaxSet};
use libs::once_cell::sync::Lazy;

use crate::config::Config;

pub const CLASS_STYLE: ClassStyle = ClassStyle::SpacedPrefixed { prefix: "z-" };

lazy_static! {
pub static ref SYNTAX_SET: SyntaxSet = {
let ss: SyntaxSet =
from_binary(include_bytes!("../../../sublime/syntaxes/newlines.packdump"));
ss
};
pub static ref THEME_SET: ThemeSet =
from_binary(include_bytes!("../../../sublime/themes/all.themedump"));
}
pub static SYNTAX_SET: Lazy<SyntaxSet> =
Lazy::new(|| from_binary(include_bytes!("../../../sublime/syntaxes/newlines.packdump")));

pub static THEME_SET: Lazy<ThemeSet> =
Lazy::new(|| from_binary(include_bytes!("../../../sublime/themes/all.themedump")));

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum HighlightSource {
Expand Down
4 changes: 2 additions & 2 deletions components/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ mod config;
pub mod highlighting;
mod theme;

use std::path::Path;

pub use crate::config::{
languages::LanguageOptions, link_checker::LinkChecker, search::Search, slugify::Slugify,
taxonomies::Taxonomy, Config,
};
use errors::Result;

use std::path::Path;

/// Get and parse the config.
/// If it doesn't succeed, exit
pub fn get_config(filename: &Path) -> Result<Config> {
Expand Down
4 changes: 2 additions & 2 deletions components/config/src/theme.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::collections::HashMap;
use std::path::Path;

use serde_derive::{Deserialize, Serialize};
use toml::Value as Toml;
use libs::toml::Value as Toml;
use serde::{Deserialize, Serialize};

use errors::{bail, Result};
use utils::fs::read_file;
Expand Down
8 changes: 2 additions & 6 deletions components/errors/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
[package]
name = "errors"
version = "0.1.0"
authors = ["Vincent Prouillet <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
tera = "1"
toml = "0.5"
image = "0.23"
syntect = "4"
libs = { path = "../libs" }
2 changes: 2 additions & 0 deletions components/errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::convert::Into;
use std::error::Error as StdError;
use std::fmt;

use libs::{image, syntect, tera, toml};

#[derive(Debug)]
pub enum ErrorKind {
Msg(String),
Expand Down
15 changes: 4 additions & 11 deletions components/front_matter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
[package]
name = "front_matter"
version = "0.1.0"
authors = ["Vincent Prouillet <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
tera = "1"
chrono = "0.4"
serde = "1"
serde_derive = "1"
serde_yaml = "0.8"
toml = "0.5"
regex = "1"
lazy_static = "1"
serde = {version = "1.0", features = ["derive"] }

errors = { path = "../errors" }
utils = { path = "../utils" }
libs = { path = "../libs" }

[dev-dependencies]
test-case = "1"
test-case = "1" # TODO: can we solve that usecase in src/page.rs in a simpler way? A custom macro_rules! maybe
29 changes: 16 additions & 13 deletions components/front_matter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
use lazy_static::lazy_static;
use serde_derive::{Deserialize, Serialize};
use std::path::Path;

use libs::once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};

use errors::{bail, Error, Result};
use regex::Regex;
use std::path::Path;
use libs::regex::Regex;
use libs::{serde_yaml, toml};

mod page;
mod section;

pub use page::PageFrontMatter;
pub use section::SectionFrontMatter;

lazy_static! {
static ref TOML_RE: Regex = Regex::new(
r"^[[:space:]]*\+\+\+(\r?\n(?s).*?(?-s))\+\+\+[[:space:]]*(?:$|(?:\r?\n((?s).*(?-s))$))"
static TOML_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r"^[[:space:]]*\+\+\+(\r?\n(?s).*?(?-s))\+\+\+[[:space:]]*(?:$|(?:\r?\n((?s).*(?-s))$))",
)
.unwrap();
static ref YAML_RE: Regex = Regex::new(
r"^[[:space:]]*---(\r?\n(?s).*?(?-s))---[[:space:]]*(?:$|(?:\r?\n((?s).*(?-s))$))"
)
.unwrap();
}
.unwrap()
});

static YAML_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^[[:space:]]*---(\r?\n(?s).*?(?-s))---[[:space:]]*(?:$|(?:\r?\n((?s).*(?-s))$))")
.unwrap()
});

pub enum RawFrontMatter<'a> {
Toml(&'a str),
Expand Down
8 changes: 4 additions & 4 deletions components/front_matter/src/page.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::collections::HashMap;

use chrono::prelude::*;
use serde_derive::Deserialize;
use tera::{Map, Value};
use libs::chrono::prelude::*;
use libs::tera::{Map, Value};
use serde::Deserialize;

use errors::{bail, Result};
use utils::de::{fix_toml_dates, from_toml_datetime};
Expand Down Expand Up @@ -152,7 +152,7 @@ impl Default for PageFrontMatter {
mod tests {
use super::PageFrontMatter;
use super::RawFrontMatter;
use tera::to_value;
use libs::tera::to_value;
use test_case::test_case;

#[test_case(&RawFrontMatter::Toml(r#" "#); "toml")]
Expand Down
4 changes: 2 additions & 2 deletions components/front_matter/src/section.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde_derive::{Deserialize, Serialize};
use tera::{Map, Value};
use libs::tera::{Map, Value};
use serde::{Deserialize, Serialize};

use super::{InsertAnchor, SortBy};
use errors::Result;
Expand Down
15 changes: 3 additions & 12 deletions components/imageproc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
[package]
name = "imageproc"
version = "0.1.0"
authors = ["Vojtěch Král <[email protected]>"]
edition = "2018"
edition = "2021"

[dependencies]
lazy_static = "1"
regex = "1.0"
tera = "1"
image = "0.23"
rayon = "1"
webp = "0.2"
serde = { version = "1", features = ["derive"] }
svg_metadata = "0.4.1"

errors = { path = "../errors" }
utils = { path = "../utils" }
config = { path = "../config" }
libs = { path = "../libs" }

[dev-dependencies]
# TODO: prune
serde_json = "1"
site = { path = "../site" }
tempfile = "3"
Loading