aboutsummaryrefslogtreecommitdiff
path: root/src/render.c
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-11-29 19:53:34 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-11-29 19:53:34 +0300
commit8e07de9d952f8f27273296f1b6ae58550ce1e98b (patch)
treec653d6d2b4a2e2251ce0ff44ad4740d91e20b1da /src/render.c
parentef0a23b0636a8c7f4a3c802ff76645261e8b225f (diff)
downloadrevela-8e07de9d952f8f27273296f1b6ae58550ce1e98b.tar.gz
revela-8e07de9d952f8f27273296f1b6ae58550ce1e98b.zip
Update adjacent images to inserted/removed
Now the program checks if the html of the next and previous images was updated if a new image was inserted or an old image removed, and updates them if needed. Also make rmextra and filesync respect dry run mode.
Diffstat (limited to 'src/render.c')
-rw-r--r--src/render.c64
1 files changed, 39 insertions, 25 deletions
diff --git a/src/render.c b/src/render.c
index 79fb543..7008e50 100644
--- a/src/render.c
+++ b/src/render.c
@@ -107,6 +107,12 @@ render_set_album_vars(struct render *r, struct album *album)
years_push_album(r->years, album);
vector_push(r->albums, album->map);
+ /*
+ * The common vars for the images in this album; used by both the album
+ * template and the image template.
+ */
+ hashmap_insert(r->common_vars, "album", album->map);
+
return true;
}
@@ -127,24 +133,19 @@ render(struct env *env, const char *tmpl, const char *opath,
return ok;
}
-#define RENDER_MAKE_START \
- bool ok = true; \
- int isupdate = file_is_uptodate(path, &r->modtime); \
- if (isupdate == -1) return false; \
- if (isupdate == 1) return true; \
- log_print(LOG_INFO, "Rendering %s...", path); \
- if (r->dry_run) goto done
-
-#define RENDER_MAKE_END \
- setdatetime(path, &r->modtime); \
-done: \
- log_printf(LOG_INFO, " done.\n"); \
- return ok
-
bool
render_make_index(struct render *r, const char *path)
{
- RENDER_MAKE_START;
+ bool ok = true;
+ if (r->albums_updated == 0) {
+ int isupdate = file_is_uptodate(path, &r->modtime);
+ if (isupdate == -1) return false;
+ if (isupdate == 1) return true;
+ }
+
+ log_printl(LOG_INFO, "Rendering %s", path);
+
+ if (r->dry_run) goto done;
hashmap_insert(r->common_vars, "years", r->years);
hashmap_insert(r->common_vars, "albums", r->years);
@@ -152,35 +153,48 @@ render_make_index(struct render *r, const char *path)
hashmap_remove(r->common_vars, "years");
hashmap_remove(r->common_vars, "albums");
- RENDER_MAKE_END;
+ setdatetime(path, &r->modtime);
+done:
+ return ok;
}
bool
render_make_album(struct render *r, const char *path, const struct album *album)
{
- if (!r->dry_run) hashmap_insert(r->common_vars, "album", album->map);
+ bool ok = true;
+ if (album->images_updated == 0) {
+ int isupdate = file_is_uptodate(path, &r->modtime);
+ if (isupdate == -1) return false;
+ if (isupdate == 1) return true;
+ }
+
+ log_printl(LOG_INFO, "Rendering %s", path);
- RENDER_MAKE_START;
+ if (r->dry_run) goto done;
ok = render(r->env, "album.html", path, r->common_vars);
- /*
- * Since we actually still want this album's map for the image inside the
- * album, we don't remove it.
- */
- RENDER_MAKE_END;
+ setdatetime(path, &r->modtime);
+done:
+ return ok;
}
bool
render_make_image(struct render *r, const char *path, const struct image *image)
{
- RENDER_MAKE_START;
+ bool ok = true;
+
+ log_printl(LOG_INFO, "Rendering %s", path);
+
+ if (r->dry_run) goto done;
hashmap_insert(r->common_vars, "image", image->map);
ok = render(r->env, "image.html", path, r->common_vars);
hashmap_remove(r->common_vars, "image");
- RENDER_MAKE_END;
+ setdatetime(path, &r->modtime);
+done:
+ return ok;
}
bool