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. # so the date can be formatted by the browser.
# format: https://docs.rs/chrono/latest/chrono/format/strftime/index.html#specifiers # format: https://docs.rs/chrono/latest/chrono/format/strftime/index.html#specifiers
js_enable = true # enable javascript (required for above) js_enable = true # enable javascript (required for above)
default_color = "#f5c2e7" # default embed color, optional
[rss] [rss]
enable = false # serve an rss field under /feed.xml enable = false # serve an rss field under /feed.xml

View file

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

View file

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

View file

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