diff options
Diffstat (limited to 'generators.c')
| -rw-r--r-- | generators.c | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/generators.c b/generators.c index a3abe24..3639309 100644 --- a/generators.c +++ b/generators.c @@ -54,12 +54,12 @@ generate_image (TGallerySetup *setup, *img_src = item->thumbnail; if (items->type == GALLERY_TYPE_INDEX) - *img_src = item->thumbnail; + *img_src = item->thumbnail; else - if (items->type == GALLERY_TYPE_ALBUM) - *img_src = item->path; - - img_src_full = g_strconcat (items->base_dir, "/", *img_src, NULL); + if (items->type == GALLERY_TYPE_ALBUM) + *img_src = (item->path == NULL && item->preview) ? item->preview : item->path; + + img_src_full = g_strconcat (items->base_dir, "/", *img_src, NULL); get_image_sizes (img_src_full, img_w, img_h); if ((img_w > 0) && (img_h > 0)) { @@ -90,8 +90,10 @@ generate_image (TGallerySetup *setup, if (items->type == GALLERY_TYPE_ALBUM) { s1 = g_path_get_dirname (dst); - big_dst = g_strconcat (s1, "/", IMG_BIG_DIR, "/", *img_src, NULL); + s2 = g_path_get_basename (*img_src); + big_dst = g_strconcat (s1, "/", IMG_BIG_DIR, "/", s2, NULL); g_free (s1); + g_free (s2); if (item->preview == NULL) { /* No preview image supplied, generate it from original */ @@ -453,6 +455,7 @@ write_html_image (TGallerySetup *setup, TAlbum *parent; int i; char *s1, *s2, *s3; + char *imgname; char *b; gboolean res; int level; @@ -472,8 +475,9 @@ write_html_image (TGallerySetup *setup, buffer = malloc (BUFFER_SIZE); s1 = g_path_get_dirname (dst); - big_dst = g_strconcat (s1, "/", IMG_BIG_DIR, "/", item->path, NULL); - orig_dst = g_strconcat (s1, "/", IMG_ORIG_DIR, "/", item->path, NULL); + imgname = (item->path == NULL && item->preview) ? g_path_get_basename (item->preview) : g_strdup (item->path); + big_dst = g_strconcat (s1, "/", IMG_BIG_DIR, "/", imgname, NULL); + orig_dst = g_strconcat (s1, "/", IMG_ORIG_DIR, "/", imgname, NULL); g_free (s1); buf_img_fullsize_link = malloc (BUFFER_SIZE); memset (buf_img_fullsize_link, 0, BUFFER_SIZE); @@ -538,7 +542,7 @@ write_html_image (TGallerySetup *setup, /* Simple placeholders */ if (strstr (b, "<!-- $(FILE_NAME) -->")) - str_replace (&b, "<!-- $(FILE_NAME) -->", item->path); + str_replace (&b, "<!-- $(FILE_NAME) -->", imgname); if (strstr (b, "<!-- $(TITLE) -->") && item->title) str_replace (&b, "<!-- $(TITLE) -->", item->title); if (strstr (b, "<!-- $(DESCRIPTION) -->") && item->title_description) @@ -554,7 +558,7 @@ write_html_image (TGallerySetup *setup, g_free (s1); } if (strstr (b, "<!-- $(NAV_BAR) -->")) { - s1 = g_strconcat (item->title, " (", item->path, ")", NULL); + s1 = g_strconcat (item->title, " (", imgname, ")", NULL); parent = parent_items; level = 0; while (parent) { @@ -570,12 +574,12 @@ write_html_image (TGallerySetup *setup, g_free (s1); } if (strstr (b, "<!-- $(IMG_SRC_BIG) -->")) { - s1 = g_strconcat (IMG_BIG_DIR, "/", item->path, NULL); + s1 = g_strconcat (IMG_BIG_DIR, "/", imgname, NULL); str_replace (&b, "<!-- $(IMG_SRC_BIG) -->", s1); g_free (s1); } if (strstr(b, "<!-- $(IMG_SRC_FULL) -->")) { - s1 = g_strconcat (IMG_ORIG_DIR, "/", item->path, NULL); + s1 = g_strconcat (IMG_ORIG_DIR, "/", imgname, NULL); str_replace (&b, "<!-- $(IMG_SRC_FULL) -->", s1); g_free (s1); } @@ -654,18 +658,22 @@ write_html_image (TGallerySetup *setup, if (strstr (b, "<!-- $(LINK_NEXT) -->")) { if (next_item) { - s1 = g_strconcat (next_item->path, ".html", NULL); + s2 = (next_item->path == NULL && next_item->preview) ? g_path_get_basename (next_item->preview) : g_strdup (next_item->path); + s1 = g_strconcat (s2, ".html", NULL); str_replace (&b, "<!-- $(LINK_NEXT) -->", s1); g_free (s1); + g_free (s2); } else str_replace (&b, "<!-- $(LINK_NEXT) -->", "index.html"); } if (strstr(b, "<!-- $(LINK_PREV) -->")) { if (previous_item) { - s1 = g_strconcat (previous_item->path, ".html", NULL); + s2 = (previous_item->path == NULL && previous_item->preview) ? g_path_get_basename (previous_item->preview) : g_strdup (previous_item->path); + s1 = g_strconcat (s2, ".html", NULL); str_replace (&b, "<!-- $(LINK_PREV) -->", s1); g_free (s1); + g_free (s2); } else str_replace (&b, "<!-- $(LINK_PREV) -->", "index.html"); @@ -689,6 +697,7 @@ write_html_image (TGallerySetup *setup, free (big_dst); free (orig_dst); free (buf_img_fullsize_link); + g_free (imgname); free_exif_data (exif); return res; } @@ -716,6 +725,7 @@ build_tree (TGallerySetup *setup, char *img_big_dir; char *img_orig_dir; char *template; + char *imgname; gboolean res; int i; @@ -861,14 +871,16 @@ build_tree (TGallerySetup *setup, fprintf (stderr, "build_tree: error getting item %d\n", i); continue; } - if (setup->verbose) printf ("Writing '%s.html' ...", item->path); + imgname = (item->path == NULL && item->preview) ? g_path_get_basename (item->preview) : g_strdup (item->path); + if (setup->verbose) printf ("Writing '%s.html' ...", imgname); s1 = g_strconcat (setup->real_templates_dir, "/", setup->template_photo, NULL); - s2 = g_strconcat (items->base_dir, "/", item->path, NULL); - s3 = g_strconcat (dst_dir, "/", item->path, ".html", NULL); + s2 = g_strconcat (items->base_dir, "/", (item->path == NULL && item->preview) ? item->preview : item->path, NULL); + s3 = g_strconcat (dst_dir, "/", imgname, ".html", NULL); res = write_html_image (setup, s1, s2, s3, item, items); g_free (s1); g_free (s2); g_free (s3); + g_free (imgname); if (! res ) continue; if (setup->verbose) printf (" done.\n"); } |
