some fixes for album html rendering
This commit is contained in:
parent
9434eb835d
commit
53a6c34785
4 changed files with 28 additions and 26 deletions
|
@ -3,7 +3,6 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if root_path %}
|
{% if root_path %}
|
||||||
<h1>
|
<h1>
|
||||||
<a href="{{root_path}}">Home</a>
|
|
||||||
{% for crumb in breadcrumbs %}
|
{% for crumb in breadcrumbs %}
|
||||||
/ <a href="{{crumb.path}}">{{crumb.name}}</a>
|
/ <a href="{{crumb.path}}">{{crumb.name}}</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -12,9 +11,9 @@
|
||||||
<hr>
|
<hr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if album_dir.description %}
|
{% if description %}
|
||||||
<div class="caption">
|
<div class="caption">
|
||||||
{{ album_dir.description | safe }}
|
{{ description | safe }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@
|
||||||
<a href="{{child.name}}/">
|
<a href="{{child.name}}/">
|
||||||
<div>
|
<div>
|
||||||
<img
|
<img
|
||||||
src="{{child.cover_thumbnail_path}}" />
|
src="{{child.name}}/{{child.cover_thumbnail_path}}" />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{{child.name}}
|
{{child.name}}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use image::imageops::FilterType;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::{OsStr, OsString};
|
use std::ffi::OsStr;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use tera::Tera;
|
use tera::Tera;
|
||||||
|
@ -17,7 +17,7 @@ const IMG_RESIZE_FILTER: FilterType = FilterType::Lanczos3;
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
struct Breadcrumb {
|
struct Breadcrumb {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
name: OsString,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Tera context for album pages
|
/// A Tera context for album pages
|
||||||
|
@ -26,15 +26,13 @@ struct AlbumContext {
|
||||||
// Path required to get back to the root album
|
// Path required to get back to the root album
|
||||||
root_path: PathBuf,
|
root_path: PathBuf,
|
||||||
|
|
||||||
// TODO: Do we actualy need the whole albumDir? Probably better off pulling data we need out of
|
name: String,
|
||||||
// it.
|
description: String,
|
||||||
// album_dir: AlbumDir,
|
|
||||||
name: OsString,
|
|
||||||
|
|
||||||
// TODO: images
|
// TODO: images
|
||||||
|
|
||||||
// Path to the cover image thumbnail within /slides/. Used when linking to an album from a
|
// Path to the cover image thumbnail within /slides/, relative to the album dir. Used when
|
||||||
// parent album
|
// linking to an album from a parent album
|
||||||
cover_thumbnail_path: PathBuf,
|
cover_thumbnail_path: PathBuf,
|
||||||
|
|
||||||
// list of:
|
// list of:
|
||||||
|
@ -50,9 +48,9 @@ impl TryFrom<&AlbumDir> for AlbumContext {
|
||||||
type Error = anyhow::Error;
|
type Error = anyhow::Error;
|
||||||
|
|
||||||
fn try_from(album: &AlbumDir) -> anyhow::Result<Self> {
|
fn try_from(album: &AlbumDir) -> anyhow::Result<Self> {
|
||||||
let name: OsString = match album.path.file_name() {
|
let name: String = match album.path.file_name() {
|
||||||
Some(n) => n.to_os_string(),
|
Some(n) => n.to_string_lossy().to_string(),
|
||||||
None => OsString::new(),
|
None => String::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Build breadcrumbs
|
// Build breadcrumbs
|
||||||
|
@ -65,7 +63,7 @@ impl TryFrom<&AlbumDir> for AlbumContext {
|
||||||
relpath.push("..");
|
relpath.push("..");
|
||||||
breadcrumbs.push(Breadcrumb {
|
breadcrumbs.push(Breadcrumb {
|
||||||
path: relpath.clone(),
|
path: relpath.clone(),
|
||||||
name: filename.into(),
|
name: filename.to_string_lossy().to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +79,7 @@ impl TryFrom<&AlbumDir> for AlbumContext {
|
||||||
|
|
||||||
// Pick a cover image thumbnail and build a path to it
|
// Pick a cover image thumbnail and build a path to it
|
||||||
let cover_thumbnail_path = match &album.cover {
|
let cover_thumbnail_path = match &album.cover {
|
||||||
Some(i) => i.path.clone(),
|
Some(i) => Path::new("slides").join(&i.thumb_filename),
|
||||||
None => PathBuf::from(""),
|
None => PathBuf::from(""),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -93,6 +91,7 @@ impl TryFrom<&AlbumDir> for AlbumContext {
|
||||||
|
|
||||||
Ok(AlbumContext {
|
Ok(AlbumContext {
|
||||||
name,
|
name,
|
||||||
|
description: album.description.clone(),
|
||||||
breadcrumbs,
|
breadcrumbs,
|
||||||
root_path,
|
root_path,
|
||||||
children,
|
children,
|
||||||
|
@ -121,7 +120,7 @@ pub fn generate(root_path: &PathBuf) -> anyhow::Result<PathBuf> {
|
||||||
env::set_current_dir(root_path)?;
|
env::set_current_dir(root_path)?;
|
||||||
let album = AlbumDir::try_from(root_path)?;
|
let album = AlbumDir::try_from(root_path)?;
|
||||||
|
|
||||||
fs::create_dir(&config.output_dir)?;
|
fs::create_dir_all(&config.output_dir)?;
|
||||||
copy_static(&config)?;
|
copy_static(&config)?;
|
||||||
generate_images(&config, &album)?;
|
generate_images(&config, &album)?;
|
||||||
generate_html(&config, &album)?;
|
generate_html(&config, &album)?;
|
||||||
|
@ -136,7 +135,9 @@ fn copy_static(config: &Config) -> anyhow::Result<()> {
|
||||||
fs_extra::dir::copy(
|
fs_extra::dir::copy(
|
||||||
"_static",
|
"_static",
|
||||||
dst,
|
dst,
|
||||||
&fs_extra::dir::CopyOptions::new().content_only(true),
|
&fs_extra::dir::CopyOptions::new()
|
||||||
|
.content_only(true)
|
||||||
|
.overwrite(true),
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,12 +45,14 @@ impl AlbumDir {
|
||||||
let _conents = fs::read_to_string(entry_path)?;
|
let _conents = fs::read_to_string(entry_path)?;
|
||||||
// TODO: render markdown
|
// TODO: render markdown
|
||||||
todo!();
|
todo!();
|
||||||
} else if filename.to_string_lossy().starts_with("cover") {
|
} else {
|
||||||
|
if filename.to_string_lossy().starts_with("cover") {
|
||||||
cover = Some(Image::new(
|
cover = Some(Image::new(
|
||||||
entry_path.strip_prefix(&root)?.to_path_buf(),
|
entry_path.strip_prefix(&root)?.to_path_buf(),
|
||||||
String::new(),
|
String::new(),
|
||||||
)?);
|
)?);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
let reader = ImageReader::open(&entry_path)?.with_guessed_format()?;
|
let reader = ImageReader::open(&entry_path)?.with_guessed_format()?;
|
||||||
if reader.format().is_some() {
|
if reader.format().is_some() {
|
||||||
// Found an image
|
// Found an image
|
||||||
|
|
|
@ -14,8 +14,8 @@ fn main() -> anyhow::Result<()> {
|
||||||
println!("Album created in {}", album_path.display());
|
println!("Album created in {}", album_path.display());
|
||||||
}
|
}
|
||||||
Commands::Generate { quick } => {
|
Commands::Generate { quick } => {
|
||||||
println!("Generate, quick: {quick}");
|
let path = generate(&album_path.to_path_buf())?;
|
||||||
generate(&album_path.to_path_buf())?;
|
println!("Album site generated in {}", path.display());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue