init command
This commit is contained in:
parent
5debb179ca
commit
d097116c37
11 changed files with 335 additions and 3 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -7,6 +7,6 @@ dist
|
||||||
/target
|
/target
|
||||||
|
|
||||||
# Project specific files
|
# Project specific files
|
||||||
test_album
|
test_album*
|
||||||
DESIGN.md
|
DESIGN.md
|
||||||
TODO.md
|
TODO.md
|
||||||
|
|
21
Cargo.lock
generated
21
Cargo.lock
generated
|
@ -128,6 +128,7 @@ version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -165,6 +166,26 @@ dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "2.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "2.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.18"
|
version = "1.0.18"
|
||||||
|
|
|
@ -10,3 +10,4 @@ edition = "2024"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "^1.0"
|
anyhow = "^1.0"
|
||||||
clap = { version = "^4.5", features = ["derive"] }
|
clap = { version = "^4.5", features = ["derive"] }
|
||||||
|
thiserror = "^2.0"
|
||||||
|
|
55
resources/skel/_templates/album.html
Normal file
55
resources/skel/_templates/album.html
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
{% if not album_dir.is_root %}
|
||||||
|
<h1>
|
||||||
|
<a href="{{root_path}}">Home</a>
|
||||||
|
{% for href, name in breadcrumbs %}
|
||||||
|
/ <a href="{{href}}">{{name}}</a>
|
||||||
|
{% endfor %}
|
||||||
|
/ {{album_dir.path.name}}
|
||||||
|
</h1>
|
||||||
|
<hr>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if album_dir.description %}
|
||||||
|
<div class="caption">
|
||||||
|
{{ album_dir.description | safe }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if album_dir.children %}
|
||||||
|
<h2>Albums</h2>
|
||||||
|
<div id="album-children">
|
||||||
|
{% for child in album_dir.children %}
|
||||||
|
<div class="album">
|
||||||
|
<a href="{{child.path.name}}/">
|
||||||
|
<div>
|
||||||
|
{% if child.cover_path %}
|
||||||
|
<img
|
||||||
|
src="{{child.cover_path.path.parent.relative_to(album_dir.path)}}/slides/{{child.cover_path.thumbnail_filename()}}" />
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{{child.path.name}}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if album_dir.images %}
|
||||||
|
{% if album_dir.children %}
|
||||||
|
<h2>Photos</h2>
|
||||||
|
{% endif %}
|
||||||
|
<div id="album-photos">
|
||||||
|
{% for image in album_dir.images %}
|
||||||
|
<div class="thumbnail">
|
||||||
|
<a href="slides/{{image.html_filename()}}">
|
||||||
|
<img src="slides/{{image.thumbnail_filename()}}" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
24
resources/skel/_templates/base.html
Normal file
24
resources/skel/_templates/base.html
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>My Photos</title>
|
||||||
|
<link rel="stylesheet" href="{{ root_path }}/static/index.css" type="text/css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="header">
|
||||||
|
<a href="{{ root_path }}">
|
||||||
|
<h1>My Photos</h1>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div id="content">
|
||||||
|
{% block content %}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
{% block js %}
|
||||||
|
{% endblock %}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
54
resources/skel/_templates/photo.html
Normal file
54
resources/skel/_templates/photo.html
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
// Do left/right navigation on keypresses
|
||||||
|
document.onkeydown = function(event) {
|
||||||
|
if (event.key == "ArrowLeft") {
|
||||||
|
{% if prev_image %}
|
||||||
|
location.href = "{{prev_image.html_filename()}}";
|
||||||
|
{% endif %}
|
||||||
|
} else if (event.key == "ArrowRight") {
|
||||||
|
{% if next_image %}
|
||||||
|
location.href = "{{next_image.html_filename()}}";
|
||||||
|
{% endif %}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div id="photo">
|
||||||
|
<img src="{{image_path.display_filename()}}" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="nav">
|
||||||
|
<div>
|
||||||
|
{% if prev_image %}
|
||||||
|
<a href="{{prev_image.html_filename()}}">
|
||||||
|
<i class="arrow arrow-left"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<a href="..">
|
||||||
|
<i class="arrow arrow-up"></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{% if next_image %}
|
||||||
|
<a href="{{next_image.html_filename()}}">
|
||||||
|
<i class="arrow arrow-right"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="photo-description" class="caption">
|
||||||
|
{% if image_path.description %}
|
||||||
|
{{ image_path.description | safe }}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="download">
|
||||||
|
<a href="../{{image_path.path.name}}">view full size</a>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
9
resources/skel/photojawn.conf.yml
Normal file
9
resources/skel/photojawn.conf.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Max size of thumbnails when viewing an album
|
||||||
|
thumbnail_size: [256, 256]
|
||||||
|
|
||||||
|
# Max size of images when viewing a single one on screen
|
||||||
|
view_size: [1024, 768]
|
||||||
|
|
||||||
|
# Directory where the generated site will be created in. All original images will be
|
||||||
|
# copied in to here with the same directory structure.
|
||||||
|
output_dir: "site"
|
112
resources/skel/static/index.css
Normal file
112
resources/skel/static/index.css
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #ba1200;
|
||||||
|
}
|
||||||
|
|
||||||
|
#header {
|
||||||
|
background-color: #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
#header * {
|
||||||
|
margin-top: 0;
|
||||||
|
text-decoration: inherit;
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
#header h1 {
|
||||||
|
padding: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content {
|
||||||
|
text-align: center;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0.5em;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content > * {
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
padding-left: 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#album-children {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#album-children > * {
|
||||||
|
margin: 1em;
|
||||||
|
padding: 0.75em;
|
||||||
|
background-color: lightgrey;
|
||||||
|
height: min-content;
|
||||||
|
border: thin solid black;
|
||||||
|
box-shadow: 0.25em 0.25em #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
#album-photos {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.thumbnail {
|
||||||
|
margin: 1em;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.thumbnail * {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav {
|
||||||
|
width: 150px;
|
||||||
|
margin: auto;
|
||||||
|
display: flex;
|
||||||
|
padding: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#nav div {
|
||||||
|
width: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#photo img {
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.caption {
|
||||||
|
max-width: 700px;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow {
|
||||||
|
border: solid black;
|
||||||
|
border-width: 0 3px 3px 0;
|
||||||
|
display: inline-block;
|
||||||
|
padding: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow-right {
|
||||||
|
transform: rotate(-45deg);
|
||||||
|
-webkit-transform: rotate(-45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow-left {
|
||||||
|
transform: rotate(135deg);
|
||||||
|
-webkit-transform: rotate(135deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow-up {
|
||||||
|
transform: rotate(-135deg);
|
||||||
|
-webkit-transform: rotate(-135deg);
|
||||||
|
}
|
1
src/lib.rs
Normal file
1
src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod skel;
|
19
src/main.rs
19
src/main.rs
|
@ -1,7 +1,22 @@
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
use photojawn::skel::make_skeleton;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
fn main() {
|
fn main() -> anyhow::Result<()> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
|
let album_path = Path::new(&cli.album_path);
|
||||||
|
|
||||||
|
match cli.subcommand {
|
||||||
|
Commands::Init {} => make_skeleton(album_path)?,
|
||||||
|
Commands::Generate { quick } => {
|
||||||
|
println!("Generate, quick: {quick}");
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
Commands::Clean {} => todo!(),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
@ -12,7 +27,7 @@ struct Cli {
|
||||||
album_path: String,
|
album_path: String,
|
||||||
|
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: Commands,
|
subcommand: Commands,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
|
|
40
src/skel.rs
Normal file
40
src/skel.rs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
use std::fs;
|
||||||
|
use std::io;
|
||||||
|
use std::path::Path;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
const BASE_TMPL: &'static [u8; 653] = include_bytes!("../resources/skel/_templates/base.html");
|
||||||
|
const ALBUM_TMPL: &'static [u8; 1682] = include_bytes!("../resources/skel/_templates/album.html");
|
||||||
|
const PHOTO_TMPL: &'static [u8; 1333] = include_bytes!("../resources/skel/_templates/photo.html");
|
||||||
|
const INDEX_CSS: &'static [u8; 1421] = include_bytes!("../resources/skel/static/index.css");
|
||||||
|
const BASE_CONFIG: &'static [u8; 315] = include_bytes!("../resources/skel/photojawn.conf.yml");
|
||||||
|
|
||||||
|
#[derive(Error, Debug)]
|
||||||
|
pub enum InitError {
|
||||||
|
#[error("Album directory already initialized - contains a photojawn.conf.yml")]
|
||||||
|
AlreadyInitialized,
|
||||||
|
#[error(transparent)]
|
||||||
|
IoError(#[from] io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn make_skeleton(album_path: &Path) -> Result<(), InitError> {
|
||||||
|
let cfg_path = album_path.join("photojawn.conf.yml");
|
||||||
|
if cfg_path.exists() {
|
||||||
|
return Err(InitError::AlreadyInitialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::create_dir_all(album_path)?;
|
||||||
|
fs::write(cfg_path, BASE_CONFIG)?;
|
||||||
|
|
||||||
|
let static_path = album_path.join("static");
|
||||||
|
fs::create_dir_all(&static_path)?;
|
||||||
|
fs::write(static_path.join("index.css"), INDEX_CSS)?;
|
||||||
|
|
||||||
|
let tmpl_path = album_path.join("_templates");
|
||||||
|
fs::create_dir_all(tmpl_path)?;
|
||||||
|
fs::write(static_path.join("base.html"), BASE_TMPL)?;
|
||||||
|
fs::write(static_path.join("album.html"), ALBUM_TMPL)?;
|
||||||
|
fs::write(static_path.join("photo.html"), PHOTO_TMPL)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue