#include "../../include/articles_p/html.h" #include "../../include/articles_p/article.h" #include "../../include/utils_op/utils.h" int gen_html_article(article_info article, char **out) { FILE *template = fopen("./static/articles/index.html", "r"); if (template == NULL) { perror("Couldn't open article template"); *out = "500"; return -1; } size_t template_size = get_file_size(template); char *template_str = malloc(template_size + 1); for (int i = 0; i < template_size; i++) template_str[i] = fgetc(template); template_str[template_size] = '\0'; char *content; process_md(article, &content); article.title = repair_spaces(article.title); int line_length = snprintf(NULL, 0, template_str, article.title, article.title, content) + 1; *out = malloc(line_length); if (*out == NULL) { *out = "500"; return -1; } snprintf(*out, line_length, template_str, article.title, article.title, content); fclose(template); free(template_str); free(content); return line_length; } int gen_html_article_list(article_info *articles, int n, char **out) { if (n == 0) { *out = "No articles found"; return 0; } *out = strdup("