Progress
FossilOrigin-Name: 52629add8a196eb6dcf025cee092cfa0a3104a54ef4e9782ddc212310cca8078
This commit is contained in:
parent
bba2ad9cda
commit
5f6c7b9108
7 changed files with 35 additions and 137 deletions
|
@ -1,4 +1,5 @@
|
|||
template
|
||||
ctemplate
|
||||
filec
|
||||
emojitoc
|
||||
**/*.cgi
|
||||
|
|
10
Makefile
10
Makefile
|
@ -24,12 +24,9 @@ MASTODONT_URL = https://fossil.nekobit.net/mastodont-c
|
|||
all: $(MASTODONT_DIR) dep_build $(TARGET)
|
||||
apache: all apache_start
|
||||
|
||||
$(TARGET): filec template $(TMPLS_C) $(TMPLS) $(PAGES_CMP) $(PAGES_C) $(PAGES_C_OBJ) $(OBJ) $(HEADERS)
|
||||
$(TARGET): filec ctemplate $(TMPLS_C) $(TMPLS) $(PAGES_CMP) $(PAGES_C) $(PAGES_C_OBJ) $(OBJ) $(HEADERS)
|
||||
$(CC) -o $(TARGET) $(OBJ) $(PAGES_C_OBJ) $(LDFLAGS)
|
||||
|
||||
template: src/template/main.o
|
||||
$(CC) $(LDFLAGS) -o template $<
|
||||
|
||||
filec: src/file-to-c/main.o
|
||||
$(CC) -o filec $<
|
||||
|
||||
|
@ -40,11 +37,14 @@ emojitoc: scripts/emoji-to.o
|
|||
# Redirect stdout and stderr into separate contents as a hack
|
||||
# Let bash do the work :)
|
||||
$(PAGES_DIR)/%.ctmpl: $(PAGES_DIR)/%.tmpl $(TMPLS)
|
||||
./template $< $(notdir $*) 2> $(PAGES_DIR)/$(notdir $*).c 1> $@
|
||||
./ctemplate $< $(notdir $*) 2> $(PAGES_DIR)/$(notdir $*).c 1> $@
|
||||
|
||||
$(TMPL_DIR)/%.ctt: $(TMPL_DIR)/%.tt
|
||||
./filec $< data_$(notdir $*)_tt > $@
|
||||
|
||||
ctemplate: src/template/main.o
|
||||
$(CC) $(LDFLAGS) -o ctemplate $<
|
||||
|
||||
$(MASTODONT_DIR):
|
||||
cd ..; fossil clone $(MASTODONT_URL) || true
|
||||
cd treebird; ln -s ../mastodont-c .
|
||||
|
|
BIN
ctemplate
Executable file
BIN
ctemplate
Executable file
Binary file not shown.
|
@ -14,12 +14,16 @@ my $template = Template->new(
|
|||
|
||||
sub base_page
|
||||
{
|
||||
my ($ssn, $data) = @_;
|
||||
my ($ssn, $data, $main) = @_;
|
||||
my $result;
|
||||
|
||||
my %vars = (
|
||||
prefix => '',
|
||||
ssn => $ssn,
|
||||
title => $L10N{'EN_US'}->{'APP_NAME'},
|
||||
lang => sub { $L10N{'EN_US'}->{shift(@_)} },
|
||||
main => $main,
|
||||
sidebar_opacity => $ssn->{config}->{sidebar_opacity} / 255,
|
||||
);
|
||||
|
||||
$template->process(\$data, \%vars, \$result) ||
|
||||
|
|
120
src/base_page.c
120
src/base_page.c
|
@ -47,34 +47,10 @@ void render_base_page(struct base_page* page, FCGX_Request* req, struct session*
|
|||
HV* session_hv = perlify_session(ssn);
|
||||
XPUSHs(sv_2mortal(newRV_inc((SV*)session_hv)));
|
||||
XPUSHs(sv_2mortal(newSVpv(data_main_tt, 0)));
|
||||
XPUSHs(sv_2mortal(newSVpv(page->content, 0)));
|
||||
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
enum l10n_locale locale = l10n_normalize(ssn->config.lang);
|
||||
char* theme_str = NULL;
|
||||
const char* login_string = "<a href=\"login\" id=\"login-header\">Login / Register</a>";
|
||||
const char* sidebar_embed = "<iframe class=\"sidebar-frame\" loading=\"lazy\" src=\"/notifications_compact\"></iframe>";
|
||||
char* background_url_css = NULL;
|
||||
// Sidebar
|
||||
char* sidebar_str,
|
||||
* main_sidebar_str = NULL,
|
||||
* account_sidebar_str = NULL,
|
||||
* instance_str = NULL;
|
||||
// Mastodont, used for notifications sidebar
|
||||
struct mstdnt_storage storage = { 0 };
|
||||
struct mstdnt_notification* notifs = NULL;
|
||||
size_t notifs_len = 0;
|
||||
#define SIDEBAR_CSS_LEN 128
|
||||
char sidebar_css[SIDEBAR_CSS_LEN];
|
||||
|
||||
/* if (keyint(ssn->cookies.logged_in)) */
|
||||
/* login_string = ""; */
|
||||
|
||||
/* if (ssn->config.background_url) */
|
||||
/* { */
|
||||
/* easprintf(&background_url_css, BODY_STYLE, ssn->config.background_url); */
|
||||
/* } */
|
||||
|
||||
/* // If user is logged in */
|
||||
/* if (keystr(ssn->cookies.logged_in) && keystr(ssn->cookies.access_token)) */
|
||||
/* { */
|
||||
|
@ -113,89 +89,6 @@ void render_base_page(struct base_page* page, FCGX_Request* req, struct session*
|
|||
/* mastodont_storage_cleanup(&storage); */
|
||||
/* } */
|
||||
/* } */
|
||||
/* else { */
|
||||
/* // Construct small login page */
|
||||
/* struct quick_login_template tdata = { */
|
||||
/* .prefix = config_url_prefix, */
|
||||
/* .username = L10N[locale][L10N_USERNAME], */
|
||||
/* .password = L10N[locale][L10N_PASSWORD], */
|
||||
/* .login = L10N[locale][L10N_LOGIN_BTN], */
|
||||
/* }; */
|
||||
/* main_sidebar_str = tmpl_gen_quick_login(&tdata, NULL); */
|
||||
/* } */
|
||||
|
||||
// Combine into sidebar
|
||||
easprintf(&sidebar_str, "%s%s",
|
||||
account_sidebar_str ? account_sidebar_str : "",
|
||||
main_sidebar_str ? main_sidebar_str : "");
|
||||
|
||||
// Create instance panel
|
||||
if (g_cache.panel_html.response)
|
||||
easprintf(&instance_str, "<div class=\"static-html\" id=\"instance-panel\">%s</div>",
|
||||
(g_cache.panel_html.response ?
|
||||
g_cache.panel_html.response : ""));
|
||||
|
||||
if (ssn->config.theme && !(strcmp(ssn->config.theme, "treebird") == 0 &&
|
||||
ssn->config.themeclr == 0))
|
||||
{
|
||||
easprintf(&theme_str, "<link rel=\"stylesheet\" type=\"text/css\" href=\"/%s%s.css\">",
|
||||
ssn->config.theme,
|
||||
ssn->config.themeclr ? "-dark" : "");
|
||||
}
|
||||
|
||||
if (ssn->config.sidebar_opacity)
|
||||
{
|
||||
float sidebar_opacity = (float)ssn->config.sidebar_opacity / 255.0f;
|
||||
snprintf(sidebar_css, SIDEBAR_CSS_LEN, ":root { --sidebar-opacity: %.2f; }",
|
||||
sidebar_opacity);
|
||||
}
|
||||
|
||||
struct index_template index_tmpl = {
|
||||
.title = L10N[locale][L10N_APP_NAME],
|
||||
.sidebar_css = sidebar_css,
|
||||
.theme_str = theme_str,
|
||||
.prefix = config_url_prefix,
|
||||
.background_url = background_url_css,
|
||||
.name = L10N[locale][L10N_APP_NAME],
|
||||
.sidebar_cnt = login_string,
|
||||
.placeholder = L10N[locale][L10N_SEARCH_PLACEHOLDER],
|
||||
.search_btn = L10N[locale][L10N_SEARCH_BUTTON],
|
||||
.active_home = CAT_TEXT(page->category, BASE_CAT_HOME),
|
||||
.home = L10N[locale][L10N_HOME],
|
||||
.active_local = CAT_TEXT(page->category, BASE_CAT_LOCAL),
|
||||
.local = L10N[locale][L10N_LOCAL],
|
||||
.active_federated = CAT_TEXT(page->category, BASE_CAT_FEDERATED),
|
||||
.federated = L10N[locale][L10N_FEDERATED],
|
||||
.active_notifications = CAT_TEXT(page->category, BASE_CAT_NOTIFICATIONS),
|
||||
.notifications = L10N[locale][L10N_NOTIFICATIONS],
|
||||
.active_lists = CAT_TEXT(page->category, BASE_CAT_LISTS),
|
||||
.lists = L10N[locale][L10N_LISTS],
|
||||
.active_favourites = CAT_TEXT(page->category, BASE_CAT_FAVOURITES),
|
||||
.favourites = L10N[locale][L10N_FAVOURITES],
|
||||
.active_bookmarks = CAT_TEXT(page->category, BASE_CAT_BOOKMARKS),
|
||||
.bookmarks = L10N[locale][L10N_BOOKMARKS],
|
||||
.active_direct = CAT_TEXT(page->category, BASE_CAT_DIRECT),
|
||||
.direct = L10N[locale][L10N_DIRECT],
|
||||
.active_chats = CAT_TEXT(page->category, BASE_CAT_CHATS),
|
||||
.chats = "Chats",
|
||||
.active_config = CAT_TEXT(page->category, BASE_CAT_CONFIG),
|
||||
.config = L10N[locale][L10N_CONFIG],
|
||||
.sidebar_leftbar = page->sidebar_left,
|
||||
.instance_panel = ssn->config.instance_panel ? instance_str : "",
|
||||
.main = page->content,
|
||||
.sidebar_rightbar = sidebar_str,
|
||||
.about_link_str = "About",
|
||||
.license_link_str = "License",
|
||||
.source_link_str = "Source code",
|
||||
};
|
||||
|
||||
// char* data = tmpl_gen_index(&index_tmpl, &len);
|
||||
|
||||
/* if (!data) */
|
||||
/* { */
|
||||
/* perror("malloc"); */
|
||||
/* goto cleanup; */
|
||||
/* } */
|
||||
|
||||
// Run function
|
||||
PUTBACK;
|
||||
|
@ -205,17 +98,8 @@ void render_base_page(struct base_page* page, FCGX_Request* req, struct session*
|
|||
char* data = POPp;
|
||||
|
||||
send_result(req, NULL, "text/html", data, 0);
|
||||
|
||||
// Cleanup
|
||||
/* cleanup_all: */
|
||||
// free(data);
|
||||
cleanup:
|
||||
/* free(sidebar_str); */
|
||||
/* if (main_sidebar_str != sidebar_embed) free(main_sidebar_str); */
|
||||
/* free(account_sidebar_str); */
|
||||
/* free(background_url_css); */
|
||||
/* free(instance_str); */
|
||||
/* free(theme_str); */
|
||||
|
||||
|
||||
PUTBACK;
|
||||
FREETMPS;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,16 +1,23 @@
|
|||
<!DOCTYPE html>
|
||||
<html {{ %s : background_url }}>
|
||||
<html [% IF ssn.config.background_url %]style="background:url('[% ssn.config.background_url %]')"[% END %]>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{{ %s : title }}</title>
|
||||
<title>$title</title>
|
||||
<link rel="icon" type="image/png" href="/favicon.png">
|
||||
<link rel="stylesheet" type="text/css" href="/treebird.css">
|
||||
{{ %s : theme_str }}
|
||||
[% IF !(ssn.config.theme == "treebird" && ssn.config.themeclr == 0) %]
|
||||
<link
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
href="/[% ssn.config.theme %][% IF ssn.config.themeclr %]-dark[% END %].css">
|
||||
[% END %]
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="{{ %s : title }} is a decentralized social media platform">
|
||||
[% IF ssn.config.sidebar_opacity %]
|
||||
<style>
|
||||
{{ %s : sidebar_css }}
|
||||
:root { --sidebar-opacity: [% sidebar_opacity %]; }
|
||||
</style>
|
||||
[% END %]
|
||||
</head>
|
||||
<body>
|
||||
<div id="main-page">
|
||||
|
@ -19,7 +26,7 @@
|
|||
<svg class="leftbar-btn navbar-btn" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line></svg>
|
||||
</label>
|
||||
<a href="{{ %s : prefix }}/"><img src="/treebird_logo.png" height="42"></a>
|
||||
<span class="info">{{ %s : name }}</span>
|
||||
<span class="info">$title</span>
|
||||
<label for="rightbar-show">
|
||||
<svg class="rightbar-btn navbar-btn" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 17H2a3 3 0 0 0 3-3V9a7 7 0 0 1 14 0v5a3 3 0 0 0 3 3zm-8.27 4a2 2 0 0 1-3.46 0"></path></svg>
|
||||
</label>
|
||||
|
@ -29,7 +36,9 @@
|
|||
<input type="checkbox" class="hidden" id="searchbar-show">
|
||||
<div id="navbar-right-container">
|
||||
<div id="navbar-right">
|
||||
{{ %s : sidebar_cnt }}
|
||||
[% IF !ssn.logged_in -%]
|
||||
<a href="login" id="login-header">Login / Register</a>
|
||||
[%- END %]
|
||||
<!-- Searchbox -->
|
||||
<form action="{{ %s : prefix }}/search" method="get">
|
||||
<input type="text" class="group group-left group-inputbox" placeholder="[% lang('SEARCH_PLACEHOLDER') %]" id="searchbox" name="q"><!-- i hate HTML
|
||||
|
@ -57,19 +66,19 @@
|
|||
<li><a class="sidebarbtn {{ %s : active_config }}" href="$prefix/config">[% lang('CONFIG') %]</a></li>
|
||||
</ul>
|
||||
{{ %s : sidebar_leftbar }}
|
||||
{{ %s : instance_panel }}
|
||||
<!-- <div class="static-html" id="instance-panel"></div> -->
|
||||
<div class="mini-links">
|
||||
<a href="{{%s:prefix}}/about">{{ %s : about_link_str }}</a>
|
||||
<a href="{{%s:prefix}}/about">About</a>
|
||||
<span class="bullet-separate">•</span>
|
||||
<a href="{{%s:prefix}}/about/license">{{ %s : license_link_str }}</a>
|
||||
<a href="{{%s:prefix}}/about/license">License</a>
|
||||
<span class="bullet-separate">•</span>
|
||||
<a href="https://fossil.nekobit.net/treebird">{{ %s : source_link_str }}</a>
|
||||
<a href="https://fossil.nekobit.net/treebird">Source code</a>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<!-- Display for posts -->
|
||||
<td id="main">
|
||||
{{ %s : main }}
|
||||
$main
|
||||
</td>
|
||||
|
||||
<!-- Notifications and such -->
|
||||
|
|
Loading…
Reference in a new issue