aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-11-08 23:29:08 +0300
committerYaroslav de la Peña Smirnov <yps@yaroslavps.com>2021-11-08 23:29:08 +0300
commitabbee959bf5c87a8b2ad0b2d55d9ddb955147892 (patch)
treed1d9f09c7a650499c282d4642faa06ac171abd29
parentaf5ac2e6df9c3a9c0c7c5bd35125b81a69b68069 (diff)
downloadrevela-abbee959bf5c87a8b2ad0b2d55d9ddb955147892.tar.gz
revela-abbee959bf5c87a8b2ad0b2d55d9ddb955147892.zip
Minor fixes here and there
* Added year variable to album template * Fixed a minor leak and dangling pointer * Other small improvements
-rw-r--r--Makefile4
-rw-r--r--include/components.h2
-rw-r--r--src/components.c11
-rw-r--r--src/render.c8
-rw-r--r--src/site.c1
-rw-r--r--template-vars.md1
6 files changed, 24 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index ed44d6e..d5b07eb 100644
--- a/Makefile
+++ b/Makefile
@@ -12,6 +12,9 @@ ifdef DEBUG
BUILDIR:=build/debug
CFLAGS:=-std=c99 -O0 -g -DDEBUG $(XFLAGS)
endif
+ifdef ASAN
+CFLAGS+= -fsanitize=address -fno-omit-frame-pointer
+endif
OBJDIR=$(BUILDIR)/obj
@@ -37,6 +40,7 @@ $(OBJDIR)/%.o: %.c
$(CC) -c $(CFLAGS) $(IDIRS) -o $@ $< $(LIBS)
revela: $(ALL_OBJS)
+ mkdir -p $(@D)
$(CC) $(LDFLAGS) -o $(BUILDIR)/$@ $^ $(LIBS) $(CFLAGS)
clean:
diff --git a/include/components.h b/include/components.h
index ba5c866..c56de77 100644
--- a/include/components.h
+++ b/include/components.h
@@ -77,6 +77,8 @@ int album_cmp(const void *a, const void *b);
void album_add_image(struct album *, struct image *);
+void album_set_year(struct album *);
+
void album_destroy(void *data);
#endif
diff --git a/src/components.c b/src/components.c
index 082eab9..8937a83 100644
--- a/src/components.c
+++ b/src/components.c
@@ -199,7 +199,7 @@ album_new(struct album_config *conf, struct site_config *sconf, const char *src,
album->slug = slugify(rsrc, sconf->base_url, &album->url);
album->images = bstree_new(image_cmp, image_destroy);
album->tstamp = MAXTIME;
- album->map = hashmap_new_with_cap(8);
+ album->map = hashmap_new_with_cap(16);
album->thumbs = vector_new(128);
album->previews = vector_new(sconf->max_previews);
@@ -223,6 +223,15 @@ album_add_image(struct album *album, struct image *image)
}
void
+album_set_year(struct album *album)
+{
+ char *delim = strchr(album->datestr, '-');
+ size_t n = delim - album->datestr;
+ strncpy(album->year, album->datestr, n);
+ album->year[n] = '\0';
+}
+
+void
album_destroy(void *data)
{
struct album *album = data;
diff --git a/src/render.c b/src/render.c
index 7c72cad..acd1de2 100644
--- a/src/render.c
+++ b/src/render.c
@@ -93,6 +93,8 @@ albums_walk(struct bstnode *node, void *data)
hashmap_insert(album->map, "title", album->config->title);
hashmap_insert(album->map, "desc", album->config->desc);
hashmap_insert(album->map, "link", album->url);
+ hashmap_insert(album->map, "date", (char *)album->datestr);
+ hashmap_insert(album->map, "year", album->year);
bstree_inorder_walk(album->images->root, images_walk, NULL);
@@ -158,7 +160,7 @@ render_make_index(struct render *r, const char *path)
bool
render_make_album(struct render *r, const char *path, const struct album *album)
{
- hashmap_insert(r->common_vars, "album", album->map);
+ if (!r->dry_run) hashmap_insert(r->common_vars, "album", album->map);
RENDER_MAKE_START;
@@ -201,7 +203,7 @@ render_init(struct render *r, const char *root, struct site_config *conf,
r->modtime = tstat.st_mtim;
- if (r->dry_run) return true;
+ if (r->dry_run) goto cleanup;
r->env = env_new(tmplpath);
if (r->env == NULL) {
@@ -221,6 +223,8 @@ render_init(struct render *r, const char *root, struct site_config *conf,
bstree_inorder_walk(albums->root, albums_walk, (void *)r);
+cleanup:
+ free(tmplpath);
return true;
}
diff --git a/src/site.c b/src/site.c
index 1acdc7c..e96c52c 100644
--- a/src/site.c
+++ b/src/site.c
@@ -181,6 +181,7 @@ traverse(struct site *site, const char *path, struct stat *dstat)
}
if (album->images->root != NULL) {
+ album_set_year(album);
bstree_add(site->albums, album);
closedir(dir);
return true;
diff --git a/template-vars.md b/template-vars.md
index 2108b87..f222813 100644
--- a/template-vars.md
+++ b/template-vars.md
@@ -21,6 +21,7 @@ A very rough and dirty representation of the variables in each template.
- `desc`
- `link`
- `date`
+ - `year`
- `previews` (vector of thumbs)
- `thumbs` (vector)
- `link`