add default color

This commit is contained in:
slonkazoid 2024-07-01 02:53:04 +03:00
parent 658ddaf820
commit bd093e7c20
Signed by: slonk
SSH key fingerprint: SHA256:tbZfJX4IOvZ0LGWOWu5Ijo8jfMPi78TU7x1VoEeCIjM
4 changed files with 11 additions and 1 deletions

View file

@ -47,6 +47,7 @@ date_format = "RFC3339" # format string used to format dates in the backend
# so the date can be formatted by the browser.
# format: https://docs.rs/chrono/latest/chrono/format/strftime/index.html#specifiers
js_enable = true # enable javascript (required for above)
default_color = "#f5c2e7" # default embed color, optional
[rss]
enable = false # serve an rss field under /feed.xml

View file

@ -45,6 +45,7 @@ struct PostTemplate {
markdown_access: bool,
df: DateFormat,
js: bool,
color: Option<String>,
}
#[derive(Deserialize)]
@ -148,6 +149,11 @@ async fn post(
) -> AppResult<Response> {
match posts.get_post(&name).await? {
ReturnedPost::Rendered(meta, rendered, rendered_in) => {
let color = meta
.color
.as_ref()
.or(config.default_color.as_ref())
.cloned();
let page = PostTemplate {
meta,
rendered,
@ -155,6 +161,7 @@ async fn post(
markdown_access: config.markdown_access,
df: config.date_format.clone(),
js: config.js_enable,
color,
};
Ok(page.into_response())

View file

@ -75,6 +75,7 @@ pub struct Config {
pub markdown_access: bool,
pub date_format: DateFormat,
pub js_enable: bool,
pub default_color: Option<String>,
pub rss: RssConfig,
pub dirs: DirsConfig,
pub http: HttpConfig,
@ -90,6 +91,7 @@ impl Default for Config {
markdown_access: true,
date_format: Default::default(),
js_enable: true,
default_color: Some("#f5c2e7".into()),
// i have a love-hate relationship with serde
// it was engimatic at first, but then i started actually using it
// writing my own serialize and deserialize implementations.. spending

View file

@ -20,7 +20,7 @@
<meta property="twitter:image:src" content="{{ url }}" />
{% when None %} {% endmatch %}
<!-- prettier is annoying -->
{% match meta.color %} {% when Some with (color) %}
{% match color %} {% when Some with (color) %}
<meta name="theme-color" content="{{ color }}" />
{% when None %} {% endmatch %}
<title>{{ meta.title }}</title>