Remove page.images

This commit is contained in:
Vojtech Kral 2018-06-23 16:38:53 +02:00 committed by Vincent Prouillet
parent 42939b9a66
commit a89768dab0
7 changed files with 18 additions and 29 deletions

3
Cargo.lock generated
View file

@ -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",

View file

@ -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"

View file

@ -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)]

View file

@ -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<String>, Vec<String>) {
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<String> {
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()
}
}

View file

@ -5,7 +5,7 @@ authors = ["Vojtěch Král <vojtech@kral.hk>"]
[dependencies]
lazy_static = "1"
regex = "0.2"
regex = "1.0"
tera = "0.11.0"
image = "0.19.0"
rayon = "0.9"

View file

@ -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<u64, ImageOp>,
/// Hash collisions go here:

View file

@ -1,6 +1,8 @@
{% for img in page.images %}
<a href="{{ config.base_url }}/{{ img }}">
<img src="{{ resize_image(path=img, width=240, height=180, op="fill") }}" />
</a>
&ensp;
{% for asset in page.assets %}
{% if asset is ending_with(".jpg") %}
<a href="{{ get_url(path=asset) }}">
<img src="{{ resize_image(path=asset, width=240, height=180, op="fill") }}" />
</a>
&ensp;
{% endif %}
{% endfor %}