feat(wip): load themes dynamically from static/themes/*.css

This commit is contained in:
frosty
2026-05-10 00:00:08 -04:00
parent ba6dae676a
commit 3c856f93ed
14 changed files with 176 additions and 65 deletions

View File

@@ -2,12 +2,17 @@
#include "../Utility/Utility.h"
#include <beaker.h>
#include <stdlib.h>
#include <string.h>
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);

View File

@@ -6,6 +6,8 @@
#include "../Utility/Utility.h"
#include "Config.h"
#include <beaker.h>
#include <stdlib.h>
#include <string.h>
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);

View File

@@ -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,