Add a way to add extra HTML to the head and body at runtime.

This commit is contained in:
Bauke 2022-10-09 19:29:43 +02:00
parent ef19f53adb
commit e41763a229
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 22 additions and 2 deletions

View File

@ -110,6 +110,7 @@ pub async fn run() -> Result<()> {
groups,
user_count_group.as_ref().map(|group| group.subscribers),
)
.await
.render_to_file(&output)
.await?;
generate_css(&output).await?;

View File

@ -10,10 +10,12 @@
<link rel="stylesheet" href="/css/modern-normalize.css">
<link rel="stylesheet" href="/css/common.css">
{% block head %}{% endblock %}
{{ extra_head_html|safe }}
</head>
<body>
{% block body %}{% endblock %}
{{ extra_body_html|safe }}
</body>
</html>

View File

@ -2,7 +2,10 @@
use {
askama::Template,
async_std::{fs::write, path::PathBuf},
async_std::{
fs::{read_to_string, write},
path::PathBuf,
},
chrono::NaiveDate,
color_eyre::Result,
};
@ -13,6 +16,12 @@ use crate::{group_data::GroupDataModel, utilities::today};
#[derive(Template)]
#[template(path = "index.html")]
pub struct HomeTemplate {
/// Extra HTML to insert in the body.
pub extra_body_html: String,
/// Extra HTML to insert in the head.
pub extra_head_html: String,
/// The groups to create the table with.
pub groups: Vec<GroupDataModel>,
@ -28,8 +37,16 @@ pub struct HomeTemplate {
impl HomeTemplate {
/// Create a new [`HomeTemplate`].
pub fn new(groups: Vec<GroupDataModel>, user_count: Option<i64>) -> Self {
pub async fn new(
groups: Vec<GroupDataModel>,
user_count: Option<i64>,
) -> Self {
let extra_body_html = read_to_string("extra-body.html").await;
let extra_head_html = read_to_string("extra-head.html").await;
Self {
extra_body_html: extra_body_html.unwrap_or_default(),
extra_head_html: extra_head_html.unwrap_or_default(),
groups,
page_title: "Tildes Statistics".to_string(),
today: today(),