From 6cf51eb557727d1167008894585154eb7c17ac15 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Fri, 4 Feb 2022 03:53:09 +0000 Subject: [PATCH] Base page loader FossilOrigin-Name: e47d130a095920eee8b8645220b94e9c5914923c1679fcd16300ca6ab46e003d --- src/base_page.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ src/base_page.h | 32 ++++++++++++++++++++++++++++ src/index.c | 14 ++++++++----- 3 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 src/base_page.c create mode 100644 src/base_page.h diff --git a/src/base_page.c b/src/base_page.c new file mode 100644 index 0000000..372f793 --- /dev/null +++ b/src/base_page.c @@ -0,0 +1,56 @@ +/* + * RatFE - Lightweight frontend for Pleroma + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "base_page.h" +#include "easprintf.h" + +// Files +#include "../static/index.chtml" + +void render_base_page(struct base_page* page) +{ + enum l10n_locale locale = page->locale; + + char* data; + int len = easprintf(&data, data_index_html, + L10N[locale][L10N_APP_NAME], + L10N[locale][L10N_APP_NAME], + L10N[locale][L10N_SEARCH_PLACEHOLDER], + L10N[locale][L10N_SEARCH_BUTTON], + L10N[locale][L10N_HOME], + L10N[locale][L10N_LOCAL], + L10N[locale][L10N_FEDERATED], + L10N[locale][L10N_NOTIFICATIONS], + L10N[locale][L10N_LISTS], + L10N[locale][L10N_DIRECT], + L10N[locale][L10N_CONFIG], + page->content); + + if (!data) + { + perror("malloc"); + return; + } + + printf("Content-Length: %d\r\n\r\n", len + 1); + puts(data); + + free(data); +} diff --git a/src/base_page.h b/src/base_page.h new file mode 100644 index 0000000..7b1a2d8 --- /dev/null +++ b/src/base_page.h @@ -0,0 +1,32 @@ +/* + * RatFE - Lightweight frontend for Pleroma + * Copyright (C) 2022 Nekobit + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef BASE_PAGE_H +#define BASE_PAGE_H +#include "l10n.h" + +struct base_page +{ + enum l10n_locale locale; + char* content; + char* sidebar_right; +}; + +void render_base_page(struct base_page* page); + +#endif // BASE_PAGE_H diff --git a/src/index.c b/src/index.c index b75b083..c4a449a 100644 --- a/src/index.c +++ b/src/index.c @@ -18,9 +18,9 @@ #include #include +#include "base_page.h" #include "../config.h" #include "index.h" -#include "easprintf.h" #include "status.h" // Files @@ -32,17 +32,21 @@ void content_index(mastodont_t* api) struct mstdnt_status* statuses; struct mstdnt_storage storage; char* status_format; - int res = mastodont_timeline_public(api, NULL, &storage, &statuses, &status_count); + mastodont_timeline_public(api, NULL, &storage, &statuses, &status_count); /* Construct statuses into HTML */ status_format = construct_statuses(statuses, status_count, &statuses_html_count); if (status_format == NULL) status_format = "Error in malloc!"; + struct base_page b = { + .locale = L10N_ES_ES, + .content = status_format, + .sidebar_right = NULL + }; + /* Output */ - printf("Content-Length: %ld\r\n\r\n", - data_index_html_size + statuses_html_count + 1); - printf(data_index_html, config_canonical_name, status_format); + render_base_page(&b); /* Cleanup */ mastodont_storage_cleanup(&storage);