tikz-gallery-generator

Custum build of stapix for tikz.pablopie.xyz

Commit
07999f705c0d30d58bcbd0e8d47430ef3f19e6ae
Parent
66728d28264ad9ca9d622a571dbc6051719f6939
Author
Pablo <pablo-escobar@riseup.net>
Date

Changed the target folder

Changed the forlder where the files are dumped to

Also factored out some of the paths in the rendered HTML

Diffstat

1 file changed, 24 insertions, 11 deletions

Status File Name N° Changes Insertions Deletions
Modified src/main.rs 35 24 11
diff --git a/src/main.rs b/src/main.rs
@@ -9,6 +9,13 @@ use types::{Escaped, PictureInfo};
 
 mod types;
 
+const TARGET_PATH:  &str = "./site";
+const PAGES_PATH:   &str = "photos";
+const PHOTOS_PATH:  &str = "assets/photos";
+const THUMBS_PATH:  &str = "assets/thumbs";
+const FAVICON_PATH: &str = "assets/favicon.ico";
+const ICON_PATH:    &str = "assets/icon.svg";
+
 const PAGE_TITLE: &str = "Pablo&apos;s Photo Gallery";
 
 /// WebP image quality
@@ -58,7 +65,8 @@ fn main() -> io::Result<()> {
 fn render_gallery(pic_infos: Vec<PictureInfo>) -> io::Result<()> {
     for pic in &pic_infos {
         let mut target_path = PathBuf::new();
-        target_path.push("./assets/photos");
+        target_path.push(TARGET_PATH);
+        target_path.push(PHOTOS_PATH);
         target_path.push(&pic.file_name);
 
         if let Err(err) = fs::copy(&pic.path, &target_path) {
@@ -96,7 +104,10 @@ fn render_gallery(pic_infos: Vec<PictureInfo>) -> io::Result<()> {
 }
 
 fn render_index(pic_infos: &Vec<PictureInfo>) -> io::Result<()> {
-    let mut f = File::create("index.html")?;
+    let mut path = PathBuf::from(TARGET_PATH);
+    path.push("index.html");
+
+    let mut f = File::create(path)?;
 
     writeln!(f, "<!DOCTYPE html>")?;
     write_license(&mut f)?;
@@ -108,7 +119,7 @@ fn render_index(pic_infos: &Vec<PictureInfo>) -> io::Result<()> {
     for pic in pic_infos {
         writeln!(
             f,
-            "<link rel=\"preload\" as=\"image\" href=\"/assets/thumbs/{name}.webp\">",
+            "<link rel=\"preload\" as=\"image\" href=\"/{THUMBS_PATH}/{name}.webp\">",
             name = Escaped(&pic.file_name)
         )?;
     }
@@ -124,12 +135,12 @@ fn render_index(pic_infos: &Vec<PictureInfo>) -> io::Result<()> {
         writeln!(f, "<li>")?;
         writeln!(
             f,
-            "<a aria-label=\"{name}\" href=\"/photos/{name}.html\">",
+            "<a aria-label=\"{name}\" href=\"/{PAGES_PATH}/{name}.html\">",
             name = Escaped(&pic.file_name)
         )?;
         writeln!(
             f,
-            "<img alt=\"{alt}\" src=\"/assets/thumbs/{name}.webp\">",
+            "<img alt=\"{alt}\" src=\"/{THUMBS_PATH}/{name}.webp\">",
             alt = Escaped(&pic.alt),
             name = Escaped(&pic.file_name)
         )?;
@@ -146,7 +157,8 @@ fn render_index(pic_infos: &Vec<PictureInfo>) -> io::Result<()> {
 
 fn render_pic_page(pic: &PictureInfo) -> io::Result<()> {
     let mut path = PathBuf::new();
-    path.push("./photos/");
+    path.push(TARGET_PATH);
+    path.push(PAGES_PATH);
     path.push(pic.file_name.clone() + ".html");
 
     let mut f = match File::create(&path) {
@@ -169,7 +181,7 @@ fn render_pic_page(pic: &PictureInfo) -> io::Result<()> {
     write_head(&mut f)?;
     writeln!(
         f,
-        "<link rel=\"preload\" as=\"image\" href=\"/assets/photos/{n}\">",
+        "<link rel=\"preload\" as=\"image\" href=\"/{PHOTOS_PATH}/{n}\">",
         n = Escaped(&pic.file_name)
     )?;
     writeln!(f, "</head>")?;
@@ -182,7 +194,7 @@ fn render_pic_page(pic: &PictureInfo) -> io::Result<()> {
     writeln!(f, "<div id=\"picture-container\">")?;
     writeln!(
         f,
-        "<img alt=\"{alt}\" src=\"/assets/photos/{file_name}\">",
+        "<img alt=\"{alt}\" src=\"/{PHOTOS_PATH}/{file_name}\">",
         alt = Escaped(&pic.alt),
         file_name = Escaped(&pic.file_name)
     )?;
@@ -197,7 +209,8 @@ fn render_pic_page(pic: &PictureInfo) -> io::Result<()> {
 
 fn render_thumbnail(pic: &PictureInfo) -> io::Result<()> {
     let mut thumb_path = PathBuf::new();
-    thumb_path.push("./assets/thumbs/");
+    thumb_path.push(TARGET_PATH);
+    thumb_path.push(THUMBS_PATH);
     thumb_path.push(pic.file_name.clone() + ".webp");
 
     // Only try to render thumbnail in case the thumbnail file in the machine
@@ -263,7 +276,7 @@ fn render_thumbnail(pic: &PictureInfo) -> io::Result<()> {
 fn write_nav(f: &mut File) -> io::Result<()> {
     writeln!(f, "<header>")?;
     writeln!(f, "<nav>")?;
-    writeln!(f, "<img aria-hidden=\"true\" alt=\"Website icon\" width=\"24\" height=\"24\" src=\"/assets/icon.svg\">")?;
+    writeln!(f, "<img aria-hidden=\"true\" alt=\"Website icon\" width=\"24\" height=\"24\" src=\"/{ICON_PATH}\">")?;
     writeln!(f, "<a href=\"/index.html\">photos.pablopie.xyz</a>")?;
     writeln!(f, "</nav>")?;
     writeln!(f, "</header>")
@@ -290,7 +303,7 @@ fn write_head(f: &mut File) -> io::Result<()> {
         f,
         "<meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\">"
     )?;
-    writeln!(f, "<link rel=\"icon\" href=\"/assets/favicon.ico\" type=\"image/x-icon\" sizes=\"16x16 24x24 32x32\">")?;
+    writeln!(f, "<link rel=\"icon\" href=\"/{FAVICON_PATH}\" type=\"image/x-icon\" sizes=\"16x16 24x24 32x32\">")?;
     writeln!(f, "<link rel=\"stylesheet\" href=\"/styles.css\">")
 }