fix image pages
This commit is contained in:
parent
141ea6dc5d
commit
2bacda9de5
3 changed files with 37 additions and 38 deletions
|
@ -5,11 +5,11 @@
|
||||||
document.onkeydown = function(event) {
|
document.onkeydown = function(event) {
|
||||||
if (event.key == "ArrowLeft") {
|
if (event.key == "ArrowLeft") {
|
||||||
{% if prev_image %}
|
{% if prev_image %}
|
||||||
location.href = "{{prev_image.html_path}}";
|
location.href = "{{prev_image.html_filename}}";
|
||||||
{% endif %}
|
{% endif %}
|
||||||
} else if (event.key == "ArrowRight") {
|
} else if (event.key == "ArrowRight") {
|
||||||
{% if next_image %}
|
{% if next_image %}
|
||||||
location.href = "{{next_image.html_path}}";
|
location.href = "{{next_image.html_filename}}";
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,13 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="photo">
|
<div id="photo">
|
||||||
<img src="{{image.screen_path}}" />
|
<img src="{{image.screen_filename}}" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="nav">
|
<div id="nav">
|
||||||
<div>
|
<div>
|
||||||
{% if prev_image %}
|
{% if prev_image %}
|
||||||
<a href="{{prev_image.html_path}}">
|
<a href="{{prev_image.html_filename}}">
|
||||||
<i class="arrow arrow-left"></i>
|
<i class="arrow arrow-left"></i>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{% if next_image %}
|
{% if next_image %}
|
||||||
<a href="{{next_image.html_path}}">
|
<a href="{{next_image.html_filename}}">
|
||||||
<i class="arrow arrow-right"></i>
|
<i class="arrow arrow-right"></i>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -105,7 +105,6 @@ impl TryFrom<&AlbumDir> for AlbumContext {
|
||||||
/// A Tera context for slide (individual image) pages
|
/// A Tera context for slide (individual image) pages
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
struct SlideContext {
|
struct SlideContext {
|
||||||
// TODO: Path or String?
|
|
||||||
// Path required to get back to the root album
|
// Path required to get back to the root album
|
||||||
root_path: PathBuf,
|
root_path: PathBuf,
|
||||||
image: Image,
|
image: Image,
|
||||||
|
@ -215,23 +214,21 @@ fn generate_html(config: &Config, album: &AlbumDir) -> anyhow::Result<()> {
|
||||||
for child in album.children.iter() {
|
for child in album.children.iter() {
|
||||||
dir_queue.push_back(&child);
|
dir_queue.push_back(&child);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let all_images: Vec<&Image> = album.iter().collect();
|
for (pos, img) in album.images.iter().enumerate() {
|
||||||
for (pos, img) in all_images.iter().enumerate() {
|
|
||||||
let img: &Image = *img;
|
|
||||||
let prev_image: Option<&Image> = match pos {
|
let prev_image: Option<&Image> = match pos {
|
||||||
0 => None,
|
0 => None,
|
||||||
n => Some(&all_images[n - 1]),
|
n => Some(&album.images[n - 1]),
|
||||||
};
|
};
|
||||||
let next_image: Option<&Image> = all_images.get(pos + 1).map(|i| *i);
|
let next_image: Option<&Image> = album.images.get(pos + 1);
|
||||||
|
|
||||||
// Find the path to the root by counting the parts of the path
|
// Find the path to the root by counting the parts of the path
|
||||||
let mut path_to_root = PathBuf::new();
|
// Start with 1 .. to get out of the slides dir
|
||||||
|
let mut path_to_root = PathBuf::from("..");
|
||||||
if let Some(parent) = img.path.parent() {
|
if let Some(parent) = img.path.parent() {
|
||||||
let mut parent = parent.to_path_buf();
|
let mut parent = parent.to_path_buf();
|
||||||
while parent.pop() {
|
while parent.pop() {
|
||||||
path_to_root = path_to_root.join("..");
|
path_to_root.push("..");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,6 +245,7 @@ fn generate_html(config: &Config, album: &AlbumDir) -> anyhow::Result<()> {
|
||||||
tera.render("photo.html", &tera::Context::from_serialize(&ctx)?)?,
|
tera.render("photo.html", &tera::Context::from_serialize(&ctx)?)?,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,10 +59,11 @@ impl AlbumDir {
|
||||||
let mut description = String::new();
|
let mut description = String::new();
|
||||||
|
|
||||||
// Read in any associated description file
|
// Read in any associated description file
|
||||||
if entry_path.with_extension(".txt").exists() {
|
if entry_path.with_extension("txt").exists() {
|
||||||
description = fs::read_to_string(&entry_path)?;
|
description =
|
||||||
} else if entry_path.with_extension(".md").exists() {
|
fs::read_to_string(&entry_path.with_extension("txt"))?;
|
||||||
let _contents = fs::read(entry_path)?;
|
} else if entry_path.with_extension("md").exists() {
|
||||||
|
let _contents = fs::read(&entry_path.with_extension("md"))?;
|
||||||
// TODO: render markdown
|
// TODO: render markdown
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue