forked from mirrors/treebird
Alas, we display posts
FossilOrigin-Name: 367cd50ddff8198249f7a5b037e729e8171bfe5c36784b0e8b5447719a5927d1
This commit is contained in:
parent
4fe4e64ba9
commit
de311c8ea2
11 changed files with 159 additions and 24 deletions
2
Makefile
2
Makefile
|
@ -27,6 +27,8 @@ filec: src/file-to-c/main.o
|
|||
|
||||
$(PAGES_DIR)/index.chtml: $(PAGES_DIR)/index.html
|
||||
./filec $< data_index_html > $@
|
||||
$(PAGES_DIR)/status.chtml: $(PAGES_DIR)/status.html
|
||||
./filec $< data_status_html > $@
|
||||
|
||||
$(MASTODONT_DIR):
|
||||
git clone $(MASTODONT_URL) || true
|
||||
|
|
3
dist/ratfe.css
vendored
3
dist/ratfe.css
vendored
|
@ -8,7 +8,6 @@ body
|
|||
{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
||||
}
|
||||
|
||||
#display
|
||||
|
@ -69,7 +68,7 @@ div#content main
|
|||
div#content aside
|
||||
{
|
||||
width: 180px;
|
||||
max-width: 200px;
|
||||
min-width: 180bpx;
|
||||
background-color: #fcfcfc;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,14 +16,36 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "easprintf.h"
|
||||
|
||||
int evasprintf(char** ret, const char* format, va_list ap)
|
||||
{
|
||||
va_list ap_copy;
|
||||
va_copy(ap_copy, ap);
|
||||
|
||||
int sz = vsnprintf(NULL, 0, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
*ret = malloc(sz + 1);
|
||||
if(*ret == NULL)
|
||||
{
|
||||
perror("malloc");
|
||||
*ret = NULL;
|
||||
va_end(ap_copy);
|
||||
return -1;
|
||||
}
|
||||
|
||||
vsnprintf(*ret, sz + 1, format, ap_copy);
|
||||
|
||||
va_end(ap_copy);
|
||||
return sz;
|
||||
}
|
||||
|
||||
int easprintf(char** ret, const char* format, ...)
|
||||
{
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
return evasprintf(ret, format, ap);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,9 @@
|
|||
|
||||
#ifndef EASPRINTF_H
|
||||
#define EASPRINTF_H
|
||||
#include <stdarg.h>
|
||||
|
||||
/* Alternatives to asprintf functions, which are glibc-only/bsd functions */
|
||||
int evasprintf(char** ret, const char* format, va_list ap);
|
||||
int easprintf(char** ret, const char* format, ...);
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ int main(int argc, char** argv)
|
|||
|
||||
printf("#ifndef __%s\n", argv[ARG_VARIABLE]);
|
||||
printf("#define __%s\n", argv[ARG_VARIABLE]);
|
||||
printf("static size_t %s_size = %ld;", argv[ARG_VARIABLE], size);
|
||||
printf("static const char %s[] = {", argv[ARG_VARIABLE]);
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
|
|
22
src/index.c
22
src/index.c
|
@ -16,17 +16,35 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "../config.h"
|
||||
#include "index.h"
|
||||
#include "easprintf.h"
|
||||
#include "status.h"
|
||||
|
||||
// Files
|
||||
#include "../static/index.chtml"
|
||||
|
||||
void content_index(mastodont_t* api)
|
||||
{
|
||||
size_t status_count, statuses_html_count;
|
||||
struct mstdnt_status* statuses;
|
||||
struct mstdnt_storage storage;
|
||||
mastodont_timeline_public(api, NULL, &storage, &statuses);
|
||||
printf(data_index_html, config_canonical_name);
|
||||
char* status_format;
|
||||
mastodont_timeline_public(api, NULL, &storage, &statuses, &status_count);
|
||||
|
||||
/* Calculate statuses */
|
||||
status_format = construct_statuses(statuses, status_count, &statuses_html_count);
|
||||
if (status_format == NULL)
|
||||
status_format = "Error in malloc! Something has gone terribly wrong...";
|
||||
|
||||
/* Output */
|
||||
printf("Content-Length: %ld\r\n\r\n",
|
||||
data_index_html_size + statuses_html_count + 4);
|
||||
printf(data_index_html, config_canonical_name, status_format);
|
||||
|
||||
/* Cleanup */
|
||||
mastodont_storage_cleanup(&storage);
|
||||
free(status_format);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ int main()
|
|||
{
|
||||
char* path = getenv("PATH_INFO");
|
||||
// Content type is always HTML
|
||||
fputs("Content-type: text/html\r\n\r\n", stdout);
|
||||
fputs("Content-type: text/html\r\n", stdout);
|
||||
|
||||
// Global init
|
||||
mastodont_global_curl_init();
|
||||
|
|
65
src/status.c
Normal file
65
src/status.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "status.h"
|
||||
#include "easprintf.h"
|
||||
#include "../static/status.chtml"
|
||||
|
||||
char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size)
|
||||
{
|
||||
char* stat_html, *result = NULL;
|
||||
int curr_parse_size = 0, last_parse_size, parse_size;
|
||||
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
parse_size = easprintf(&stat_html, data_status_html,
|
||||
statuses[i].id, /* Username */
|
||||
"@who?", /* Account */
|
||||
"Public?", /* visibility */
|
||||
statuses[i].content);
|
||||
if (parse_size == -1) /* Malloc error */
|
||||
{
|
||||
if (result) free(result);
|
||||
return NULL;
|
||||
}
|
||||
last_parse_size = curr_parse_size;
|
||||
curr_parse_size += parse_size;
|
||||
|
||||
result = realloc(result, curr_parse_size + 1);
|
||||
if (result == NULL)
|
||||
{
|
||||
perror("malloc");
|
||||
free(stat_html);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Copy stat_html to result in correct position */
|
||||
strncpy(result + last_parse_size, stat_html, parse_size);
|
||||
/* Cleanup */
|
||||
free(stat_html);
|
||||
}
|
||||
|
||||
result[curr_parse_size] = '\0';
|
||||
|
||||
if (ret_size) *ret_size = curr_parse_size;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
25
src/status.h
Normal file
25
src/status.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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 STATUS_H
|
||||
#define STATUS_H
|
||||
#include <mastodont.h>
|
||||
|
||||
char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size);
|
||||
|
||||
#endif // STATUS_H
|
|
@ -27,24 +27,8 @@
|
|||
|
||||
<!-- Display for posts -->
|
||||
<main>
|
||||
<div class="status">
|
||||
<div class="profile-picture">
|
||||
<img src="ratfe_logo.png" height="64">
|
||||
</div>
|
||||
<div class="status-info">
|
||||
<div class="poster-stats">
|
||||
<span class="username">Rat user</span>
|
||||
<a class="instance-info" href="#">@ratlord@cum.desupost.soy</a>
|
||||
<span class="alignend status-visibility">
|
||||
public
|
||||
</span>
|
||||
</div>
|
||||
<span class="status-content">
|
||||
This is my first post<br><br>
|
||||
Just landed in L.A.!
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
%s
|
||||
|
||||
</main>
|
||||
|
||||
<!-- Notifications and such -->
|
||||
|
|
17
static/status.html
Normal file
17
static/status.html
Normal file
|
@ -0,0 +1,17 @@
|
|||
<div class="status">
|
||||
<div class="profile-picture">
|
||||
<img src="ratfe_logo.png" height="64">
|
||||
</div>
|
||||
<div class="status-info">
|
||||
<div class="poster-stats">
|
||||
<span class="username">%s</span>
|
||||
<a class="instance-info" href="#">%s</a>
|
||||
<span class="alignend status-visibility">
|
||||
%s
|
||||
</span>
|
||||
</div>
|
||||
<span class="status-content">
|
||||
%s
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in a new issue