Set background image

FossilOrigin-Name: db277a62fb31cfc43e4e38ca5915e1b77af042284c6cbb52c221509fb67ca8b6
This commit is contained in:
me@ow.nekobit.net 2022-04-12 15:06:55 +00:00
parent bbe110ed7b
commit 3a2d946c88
11 changed files with 50 additions and 7 deletions

9
dist/treebird20.css vendored
View file

@ -5,6 +5,12 @@
Other themes do not need to be compatible with Netsurf and older browsers or use tables,
I just wanted this to be as compatible as possible, go wild with your own themes */
*
{
margin: 0;
padding: 0;
}
html
{
background-color: #f6f6f6;
@ -12,12 +18,15 @@ html
body
{
background-attachment: fixed !important;
background-size: cover !important;
background-color: unset;
font-family: Arial, Helvetica, sans-serif;
}
#main-page
{
margin: 8px;
width: 1000px;
border-top: 0 !important;
margin-left: auto;

8
dist/treebird40.css vendored
View file

@ -5,6 +5,12 @@
Other themes do not need to be compatible with Netsurf and older browsers or use tables,
I just wanted this to be as compatible as possible, go wild with your own themes */
*
{
margin: 0;
padding: 0;
}
html
{
background-color: #f6f6f6;
@ -12,6 +18,8 @@ html
body
{
background-attachment: fixed !important;
background-size: cover !important;
background-color: unset;
font-family: Arial, Helvetica, sans-serif;
}

View file

@ -29,11 +29,14 @@
// Files
#include "../static/index.chtml"
#define BODY_STYLE "style=\"background:url('%s');\""
void render_base_page(struct base_page* page, struct session* ssn, mastodont_t* api)
{
char* cookie = getenv("HTTP_COOKIE");
enum l10n_locale locale = page->locale;
char* login_string = "<a href=\"login\" id=\"login-header\">Login / Register</a>";
char* background_url_css = NULL;
char* sidebar_str = NULL;
// Mastodont, used for notifications sidebar
struct mstdnt_storage storage = { 0 };
@ -46,8 +49,15 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t*
ssn->config.theme = ssn->cookies.theme;
if (ssn->cookies.logged_in)
login_string = "";
if (ssn->cookies.background_url)
ssn->config.background_url = ssn->cookies.background_url;
}
if (ssn->config.background_url)
{
easprintf(&background_url_css, BODY_STYLE, ssn->config.background_url);
}
// Get / Show notifications on sidebar
if (ssn->cookies.logged_in && ssn->cookies.access_token)
{
@ -75,6 +85,7 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t*
L10N[locale][L10N_APP_NAME],
ssn->config.theme,
ssn->config.themeclr ? "-dark" : "",
background_url_css ? background_url_css : "",
config_url_prefix,
L10N[locale][L10N_APP_NAME],
login_string,
@ -122,4 +133,5 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t*
free(data);
cleanup:
if (sidebar_str) free(sidebar_str);
if (background_url_css) free(background_url_css);
}

View file

@ -53,7 +53,8 @@ char* read_cookies_env(struct cookie_values* cookies)
{ "access_token", &(cookies->access_token), key_string },
{ "logged_in", &(cookies->logged_in), key_string },
{ "theme", &(cookies->theme), key_string },
{ "instance_url", &(cookies->instance_url), key_string }
{ "instance_url", &(cookies->instance_url), key_string },
{ "background_url", &(cookies->background_url), key_string },
};
do

View file

@ -26,6 +26,7 @@ struct cookie_values
char* logged_in;
char* theme;
char* instance_url;
char* background_url;
};
struct http_cookie_info

View file

@ -24,6 +24,7 @@ struct local_config
{
int changed;
char* theme;
char* background_url;
int themeclr;
int jsactions;
int jsreply;

View file

@ -58,8 +58,17 @@ int set_config_int(int* ssn,
return 1;
}
void load_config(struct session* ssn)
void load_config(struct session* ssn, mastodont_t* api)
{
if (ssn->post.theme && ssn->post.files.array_size && ssn->post.files.content[0].content_size)
{
struct mstdnt_attachment* attachments = NULL;
struct mstdnt_storage storage = { 0 };
if (try_upload_media(&storage, ssn, api, &attachments, NULL) == 0)
{
set_config_str(&(ssn->config.background_url), "background_url", attachments[0].url);
}
}
set_config_str(&(ssn->config.theme), "theme", ssn->post.theme);
set_config_int(&(ssn->config.themeclr), "themeclr", ssn->post.themeclr);

View file

@ -18,8 +18,10 @@
#ifndef LOCAL_CONFIG_SET_H
#define LOCAL_CONFIG_SET_H
#include <mastodont.h>
#include "local_config.h"
#include "session.h"
#include "attachments.h"
int set_config_str(char** ssn,
char* cookie_name,
@ -29,6 +31,6 @@ int set_config_int(int* ssn,
char* cookie_name,
char* value);
void load_config(struct session* ssn);
void load_config(struct session* ssn, mastodont_t* api);
#endif // LOCAL_CONFIG_SET_H

View file

@ -65,7 +65,7 @@ void content_config_general(struct session* ssn, mastodont_t* api, char** data)
{
char* sidebar_html = construct_config_sidebar(CONFIG_CAT_GENERAL, NULL);
load_config(ssn);
load_config(ssn, api);
struct base_page b = {
.category = BASE_CAT_CONFIG,
@ -84,7 +84,7 @@ void content_config_appearance(struct session* ssn, mastodont_t* api, char** dat
{
char* sidebar_html = construct_config_sidebar(CONFIG_CAT_APPEARANCE, NULL);
load_config(ssn);
load_config(ssn, api);
struct base_page b = {
.category = BASE_CAT_CONFIG,

View file

@ -1,5 +1,5 @@
<div class="simple-page">
<form action="appearance" method="post">
<form action="appearance" method="post" enctype="multipart/form-data">
<!-- Appearance -->
<h1>Appearance</h1>
<h3>Theme variant</h3>

View file

@ -6,7 +6,7 @@
<link rel="icon" type="image/png" href="/favicon.png">
<link rel="stylesheet" type="text/css" href="/%s%s.css">
</head>
<body>
<body %s>
<div id="main-page">
<header id="navbar">
<a href="%s/"><img src="/treebird_logo.png" height="42"></a>