Add individual group pages.
This commit is contained in:
parent
0410fd3603
commit
e4847a6c57
|
@ -19,7 +19,7 @@ use crate::{
|
|||
migrations::Migrator,
|
||||
scss::generate_css,
|
||||
snapshots::SnapshotModel,
|
||||
templates::HomeTemplate,
|
||||
templates::{GroupTemplate, HomeTemplate},
|
||||
utilities::{create_db, today},
|
||||
};
|
||||
|
||||
|
@ -117,6 +117,11 @@ pub async fn run() -> Result<()> {
|
|||
}
|
||||
.render(&output, &group.name, true)
|
||||
.await?;
|
||||
|
||||
GroupTemplate::new(&group.name)
|
||||
.await
|
||||
.render_to_file(&output)
|
||||
.await?;
|
||||
}
|
||||
|
||||
HomeTemplate::new(
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block head %}
|
||||
<link rel="stylesheet" href="/css/index.css">
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<header class="page-header">
|
||||
<img src="/tildes-statistics.png" alt="Tildes Statistics Logo">
|
||||
<h1>{{ group_name }} Statistics</h1>
|
||||
</header>
|
||||
|
||||
<main class="page-main">
|
||||
<h2>General</h2>
|
||||
|
||||
<img class="chart" src="/charts/user-count/{{ group_name }}.svg"
|
||||
alt="{{ group_name }} User Count Chart">
|
||||
</main>
|
||||
{% endblock %}
|
|
@ -37,7 +37,7 @@
|
|||
{% for group in groups %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ base_url }}/{{ group.name }}">{{ group.name }}</a>
|
||||
<a href="/{{ group.name }}">{{ group.name }}</a>
|
||||
</td>
|
||||
<td>{{ group.subscribers }}</td>
|
||||
<td>
|
||||
|
|
|
@ -10,6 +10,8 @@ use {
|
|||
color_eyre::Result,
|
||||
};
|
||||
|
||||
use async_std::fs::create_dir_all;
|
||||
|
||||
use crate::{
|
||||
group_data::GroupDataModel,
|
||||
utilities::{get_base_url, today},
|
||||
|
@ -70,3 +72,52 @@ impl HomeTemplate {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// The template for group-specific pages.
|
||||
#[derive(Template)]
|
||||
#[template(path = "group.html")]
|
||||
pub struct GroupTemplate {
|
||||
/// The base URL for links to the Tildes instance.
|
||||
pub base_url: String,
|
||||
|
||||
/// 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 group name for this group.
|
||||
pub group_name: String,
|
||||
|
||||
/// The string for the `<title>` element.
|
||||
pub page_title: String,
|
||||
|
||||
/// The date of today's snapshot.
|
||||
pub today: NaiveDate,
|
||||
}
|
||||
|
||||
impl GroupTemplate {
|
||||
/// Create a new [`GroupTemplate`].
|
||||
pub async fn new(group_name: &str) -> Self {
|
||||
let extra_body_html = read_to_string("extra-body.html").await;
|
||||
let extra_head_html = read_to_string("extra-head.html").await;
|
||||
|
||||
Self {
|
||||
base_url: get_base_url(),
|
||||
extra_body_html: extra_body_html.unwrap_or_default(),
|
||||
extra_head_html: extra_head_html.unwrap_or_default(),
|
||||
group_name: group_name.to_string(),
|
||||
page_title: "Tildes Statistics".to_string(),
|
||||
today: today(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Render the template and write it to file.
|
||||
pub async fn render_to_file(&self, parent: &PathBuf) -> Result<()> {
|
||||
let output_dir = parent.join(&self.group_name);
|
||||
create_dir_all(&output_dir).await?;
|
||||
write(output_dir.join("index.html"), self.render()?).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue