From 3c856f93ed3d1362a8b6190d9ce44b2939fca717 Mon Sep 17 00:00:00 2001 From: frosty Date: Sun, 10 May 2026 00:00:08 -0400 Subject: feat(wip): load themes dynamically from static/themes/*.css --- src/Routes/Home.c | 5 +++++ src/Routes/Images.c | 17 +++++++++++------ src/Routes/Settings.c | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 8 deletions(-) (limited to 'src/Routes') diff --git a/src/Routes/Home.c b/src/Routes/Home.c index 0534517..bf85fe1 100644 --- a/src/Routes/Home.c +++ b/src/Routes/Home.c @@ -2,12 +2,17 @@ #include "../Utility/Utility.h" #include #include +#include int home_handler(UrlParams *params) { (void)params; char *theme = get_theme(""); char *locale = get_locale(NULL); + char **themes = NULL; + int themes_count = 0; + get_available_themes(&themes, &themes_count); + TemplateContext ctx = new_context(); context_set(&ctx, "theme", theme); context_set(&ctx, "version", VERSION); diff --git a/src/Routes/Images.c b/src/Routes/Images.c index dda329c..40ab88f 100644 --- a/src/Routes/Images.c +++ b/src/Routes/Images.c @@ -6,6 +6,8 @@ #include "../Utility/Utility.h" #include "Config.h" #include +#include +#include static char *build_images_request_cache_key(const char *query, int page, const char *client_key) { @@ -67,15 +69,18 @@ int images_handler(UrlParams *params) { beaker_set_locale(&ctx, locale); const char *rate_limit_msg = beaker_get_locale_value(locale, "rate_limit"); - if (!rate_limit_msg) rate_limit_msg = "Slow down! Too many image searches from you!"; - const char *error_images_msg = beaker_get_locale_value(locale, "error_images"); - if (!error_images_msg) error_images_msg = "Error fetching images"; + if (!rate_limit_msg) + rate_limit_msg = "Slow down! Too many image searches from you!"; + const char *error_images_msg = + beaker_get_locale_value(locale, "error_images"); + if (!error_images_msg) + error_images_msg = "Error fetching images"; char ***pager_matrix = NULL; int *pager_inner_counts = NULL; - int pager_count = build_pagination(page, images_href_builder, - (void *)raw_query, &pager_matrix, - &pager_inner_counts); + int pager_count = + build_pagination(page, images_href_builder, (void *)raw_query, + &pager_matrix, &pager_inner_counts); if (pager_count > 0) { context_set_array_of_arrays(&ctx, "pagination_links", pager_matrix, pager_count, pager_inner_counts); diff --git a/src/Routes/Settings.c b/src/Routes/Settings.c index b21dd6f..eb3072b 100644 --- a/src/Routes/Settings.c +++ b/src/Routes/Settings.c @@ -32,7 +32,8 @@ int settings_handler(UrlParams *params) { char **user_engines = NULL; int user_engine_count = 0; - int has_user_pref = (get_user_engines(&user_engines, &user_engine_count) == 0); + int has_user_pref = + (get_user_engines(&user_engines, &user_engine_count) == 0); int enabled_count = 0; for (int i = 0; i < ENGINE_COUNT; i++) { @@ -77,7 +78,34 @@ int settings_handler(UrlParams *params) { context_set(&ctx, "query", query); context_set(&ctx, "theme", theme); context_set(&ctx, "locale", locale); - context_set_array_of_arrays(&ctx, "locales", locale_data, locale_count, inner_counts); + context_set_array_of_arrays(&ctx, "locales", locale_data, locale_count, + inner_counts); + + char **themes = NULL; + int themes_count = 0; + get_available_themes(&themes, &themes_count); + + if (themes_count > 0) { + char ***theme_ptrs = malloc(sizeof(char **) * themes_count); + int *theme_inner = malloc(sizeof(int) * themes_count); + for (int i = 0; i < themes_count; i++) { + theme_ptrs[i] = malloc(sizeof(char *) * 2); + theme_ptrs[i][0] = themes[i]; + theme_ptrs[i][1] = strdup(themes[i]); + if (theme_ptrs[i][1][0] >= 'a' && theme_ptrs[i][1][0] <= 'z') { + theme_ptrs[i][1][0] = theme_ptrs[i][1][0] - 'a' + 'A'; + } + theme_inner[i] = 2; + } + context_set_array_of_arrays(&ctx, "themes", theme_ptrs, themes_count, + theme_inner); + for (int i = 0; i < themes_count; i++) { + free(theme_ptrs[i][1]); + free(theme_ptrs[i]); + } + free(theme_ptrs); + free(theme_inner); + } if (enabled_count > 0) { context_set_array_of_arrays(&ctx, "enabled_engines", engine_data, -- cgit v1.3