Base page loader

FossilOrigin-Name: e47d130a095920eee8b8645220b94e9c5914923c1679fcd16300ca6ab46e003d
This commit is contained in:
me@ow.nekobit.net 2022-02-04 03:53:09 +00:00
parent bd15c39512
commit 6cf51eb557
3 changed files with 97 additions and 5 deletions

56
src/base_page.c Normal file
View file

@ -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 <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#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);
}

32
src/base_page.h Normal file
View file

@ -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 <https://www.gnu.org/licenses/>.
*/
#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

View file

@ -18,9 +18,9 @@
#include <stdlib.h>
#include <stdio.h>
#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);