Remove page.images
This commit is contained in:
parent
42939b9a66
commit
a89768dab0
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -370,7 +370,6 @@ dependencies = [
|
||||||
"errors 0.1.0",
|
"errors 0.1.0",
|
||||||
"front_matter 0.1.0",
|
"front_matter 0.1.0",
|
||||||
"globset 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"rayon 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rendering 0.1.0",
|
"rendering 0.1.0",
|
||||||
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"utils 0.1.0",
|
"utils 0.1.0",
|
||||||
|
|
|
@ -15,7 +15,6 @@ config = { path = "../config" }
|
||||||
utils = { path = "../utils" }
|
utils = { path = "../utils" }
|
||||||
rendering = { path = "../rendering" }
|
rendering = { path = "../rendering" }
|
||||||
front_matter = { path = "../front_matter" }
|
front_matter = { path = "../front_matter" }
|
||||||
imageproc = { path = "../imageproc" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
|
|
|
@ -8,7 +8,6 @@ extern crate errors;
|
||||||
extern crate config;
|
extern crate config;
|
||||||
extern crate front_matter;
|
extern crate front_matter;
|
||||||
extern crate rendering;
|
extern crate rendering;
|
||||||
extern crate imageproc;
|
|
||||||
extern crate utils;
|
extern crate utils;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -15,7 +15,6 @@ use utils::site::get_reading_analytics;
|
||||||
use utils::templates::render_template;
|
use utils::templates::render_template;
|
||||||
use front_matter::{PageFrontMatter, InsertAnchor, split_page_content};
|
use front_matter::{PageFrontMatter, InsertAnchor, split_page_content};
|
||||||
use rendering::{RenderContext, Header, render_content};
|
use rendering::{RenderContext, Header, render_content};
|
||||||
use imageproc;
|
|
||||||
|
|
||||||
use file_info::FileInfo;
|
use file_info::FileInfo;
|
||||||
|
|
||||||
|
@ -207,21 +206,13 @@ impl Page {
|
||||||
.chain_err(|| format!("Failed to render page '{}'", self.file.path.display()))
|
.chain_err(|| format!("Failed to render page '{}'", self.file.path.display()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates two vectors of asset URLs. The first one contains all asset files,
|
/// Creates a vectors of asset URLs.
|
||||||
/// the second one that which appear to be an image file.
|
fn serialize_assets(&self) -> Vec<String> {
|
||||||
fn serialize_assets(&self) -> (Vec<String>, Vec<String>) {
|
self.assets.iter()
|
||||||
let mut assets = vec![];
|
.filter_map(|asset| asset.file_name())
|
||||||
let mut images = vec![];
|
.filter_map(|filename| filename.to_str())
|
||||||
for asset in self.assets.iter() {
|
.map(|filename| self.path.clone() + filename)
|
||||||
if let Some(filename) = asset.file_name().and_then(|f| f.to_str()) {
|
.collect()
|
||||||
let url = self.path.clone() + filename;
|
|
||||||
if imageproc::file_is_img(&asset) {
|
|
||||||
images.push(url.clone());
|
|
||||||
}
|
|
||||||
assets.push(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(assets, images)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,9 +268,8 @@ impl ser::Serialize for Page {
|
||||||
state.serialize_field("next", &self.next)?;
|
state.serialize_field("next", &self.next)?;
|
||||||
state.serialize_field("toc", &self.toc)?;
|
state.serialize_field("toc", &self.toc)?;
|
||||||
state.serialize_field("draft", &self.is_draft())?;
|
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("assets", &assets)?;
|
||||||
state.serialize_field("images", &images)?;
|
|
||||||
state.end()
|
state.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ authors = ["Vojtěch Král <vojtech@kral.hk>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
regex = "0.2"
|
regex = "1.0"
|
||||||
tera = "0.11.0"
|
tera = "0.11.0"
|
||||||
image = "0.19.0"
|
image = "0.19.0"
|
||||||
rayon = "0.9"
|
rayon = "0.9"
|
||||||
|
|
|
@ -213,7 +213,7 @@ pub struct Processor {
|
||||||
resized_path: PathBuf,
|
resized_path: PathBuf,
|
||||||
resized_url: String,
|
resized_url: String,
|
||||||
/// A map of a ImageOps by their stored hash.
|
/// 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.
|
/// we need to be aware of and handle collisions ourselves.
|
||||||
img_ops: HashMap<u64, ImageOp>,
|
img_ops: HashMap<u64, ImageOp>,
|
||||||
/// Hash collisions go here:
|
/// Hash collisions go here:
|
||||||
|
|
12
docs/templates/shortcodes/gallery.html
vendored
12
docs/templates/shortcodes/gallery.html
vendored
|
@ -1,6 +1,8 @@
|
||||||
{% for img in page.images %}
|
{% for asset in page.assets %}
|
||||||
<a href="{{ config.base_url }}/{{ img }}">
|
{% if asset is ending_with(".jpg") %}
|
||||||
<img src="{{ resize_image(path=img, width=240, height=180, op="fill") }}" />
|
<a href="{{ get_url(path=asset) }}">
|
||||||
</a>
|
<img src="{{ resize_image(path=asset, width=240, height=180, op="fill") }}" />
|
||||||
 
|
</a>
|
||||||
|
 
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in a new issue