From a89768dab047970c4ceb52a4e1685445cedaf440 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Sat, 23 Jun 2018 16:38:53 +0200 Subject: [PATCH] Remove page.images --- Cargo.lock | 3 +-- components/content/Cargo.toml | 1 - components/content/src/lib.rs | 1 - components/content/src/page.rs | 26 ++++++++------------------ components/imageproc/Cargo.toml | 2 +- components/imageproc/src/lib.rs | 2 +- docs/templates/shortcodes/gallery.html | 12 +++++++----- 7 files changed, 18 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f8b96138..010ee914 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -370,7 +370,6 @@ dependencies = [ "errors 0.1.0", "front_matter 0.1.0", "globset 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "imageproc 0.1.0", "rayon 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rendering 0.1.0", "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", @@ -916,7 +915,7 @@ dependencies = [ "image 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "tera 0.11.8 (registry+https://github.com/rust-lang/crates.io-index)", "twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "utils 0.1.0", diff --git a/components/content/Cargo.toml b/components/content/Cargo.toml index e9138738..ca8cffed 100644 --- a/components/content/Cargo.toml +++ b/components/content/Cargo.toml @@ -15,7 +15,6 @@ config = { path = "../config" } utils = { path = "../utils" } rendering = { path = "../rendering" } front_matter = { path = "../front_matter" } -imageproc = { path = "../imageproc" } [dev-dependencies] tempfile = "3" diff --git a/components/content/src/lib.rs b/components/content/src/lib.rs index 4cd93fac..5d111c4e 100644 --- a/components/content/src/lib.rs +++ b/components/content/src/lib.rs @@ -8,7 +8,6 @@ extern crate errors; extern crate config; extern crate front_matter; extern crate rendering; -extern crate imageproc; extern crate utils; #[cfg(test)] diff --git a/components/content/src/page.rs b/components/content/src/page.rs index 704b0682..b77a6dbe 100644 --- a/components/content/src/page.rs +++ b/components/content/src/page.rs @@ -15,7 +15,6 @@ use utils::site::get_reading_analytics; use utils::templates::render_template; use front_matter::{PageFrontMatter, InsertAnchor, split_page_content}; use rendering::{RenderContext, Header, render_content}; -use imageproc; use file_info::FileInfo; @@ -207,21 +206,13 @@ impl Page { .chain_err(|| format!("Failed to render page '{}'", self.file.path.display())) } - /// Creates two vectors of asset URLs. The first one contains all asset files, - /// the second one that which appear to be an image file. - fn serialize_assets(&self) -> (Vec, Vec) { - let mut assets = vec![]; - let mut images = vec![]; - for asset in self.assets.iter() { - if let Some(filename) = asset.file_name().and_then(|f| f.to_str()) { - let url = self.path.clone() + filename; - if imageproc::file_is_img(&asset) { - images.push(url.clone()); - } - assets.push(url); - } - } - (assets, images) + /// Creates a vectors of asset URLs. + fn serialize_assets(&self) -> Vec { + self.assets.iter() + .filter_map(|asset| asset.file_name()) + .filter_map(|filename| filename.to_str()) + .map(|filename| self.path.clone() + filename) + .collect() } } @@ -277,9 +268,8 @@ impl ser::Serialize for Page { state.serialize_field("next", &self.next)?; state.serialize_field("toc", &self.toc)?; state.serialize_field("draft", &self.is_draft())?; - let (assets, images) = self.serialize_assets(); + let assets = self.serialize_assets(); state.serialize_field("assets", &assets)?; - state.serialize_field("images", &images)?; state.end() } } diff --git a/components/imageproc/Cargo.toml b/components/imageproc/Cargo.toml index 647873fb..7a85f1c7 100644 --- a/components/imageproc/Cargo.toml +++ b/components/imageproc/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Vojtěch Král "] [dependencies] lazy_static = "1" -regex = "0.2" +regex = "1.0" tera = "0.11.0" image = "0.19.0" rayon = "0.9" diff --git a/components/imageproc/src/lib.rs b/components/imageproc/src/lib.rs index fde98af8..810ebb3b 100644 --- a/components/imageproc/src/lib.rs +++ b/components/imageproc/src/lib.rs @@ -213,7 +213,7 @@ pub struct Processor { resized_path: PathBuf, resized_url: String, /// A map of a ImageOps by their stored hash. - /// Note that this cannot be a HashSet, because hashest handles collisions and we don't want that, + /// Note that this cannot be a HashSet, because hashset handles collisions and we don't want that, /// we need to be aware of and handle collisions ourselves. img_ops: HashMap, /// Hash collisions go here: diff --git a/docs/templates/shortcodes/gallery.html b/docs/templates/shortcodes/gallery.html index fa1c84b6..d2afc716 100644 --- a/docs/templates/shortcodes/gallery.html +++ b/docs/templates/shortcodes/gallery.html @@ -1,6 +1,8 @@ -{% for img in page.images %} - - - -   +{% for asset in page.assets %} + {% if asset is ending_with(".jpg") %} + + + +   + {% endif %} {% endfor %}