Skip to content

Commit

Permalink
Make title, subtitle configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
homeworkprod committed May 19, 2024
1 parent d63f08c commit c85fe97
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

## 0.4.0 (unreleased)

- Made title and optional subtitle configurable.

- Added generator and timestamp to page footer.

- Raised minimum supported Rust version to 1.76.0.
Expand Down
3 changes: 3 additions & 0 deletions config-example.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
title = "Title"
subtitle = "Subtitle"

[discord]
bot_token = "your-secret-bot-token"
guild_id = "your-guild-id"
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use std::path::Path;

#[derive(Debug, Deserialize)]
pub(crate) struct Config {
pub title: String,
pub subtitle: Option<String>,
pub discord: DiscordConfig,
}

Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ fn main() -> Result<()> {
let generated_at = Utc::now();

match args.output_format {
cli::OutputFormat::Html => templating::render_html(roles, generated_at, writer)?,
cli::OutputFormat::Html => {
templating::render_html(config.title, config.subtitle, roles, generated_at, writer)?
}
cli::OutputFormat::Json => model::write_roles(roles, writer)?,
cli::OutputFormat::Text => templating::render_text(roles, writer)?,
};
Expand Down
8 changes: 5 additions & 3 deletions src/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OrgaTalk Discord – Orga team roles and memberships</title>
<title>{{ title }}{% if subtitle %} – {{ subtitle }}{% endif %}</title>
<style>
:root {
--dimmed: #8e9297;
Expand Down Expand Up @@ -95,8 +95,10 @@
<body>

<main>
<h1 class="title">OrgaTalk Discord</h1>
<div class="subtitle">Orga team roles and memberships</div>
<h1 class="title">{{ title }}</h1>
{%- if subtitle %}
<div class="subtitle">{{ subtitle }}</div>
{%- endif %}

<div class="roles-count">{{ roles|length }} {% if roles|length == 1 %}Team{% else %}Teams{% endif %}</div>

Expand Down
4 changes: 4 additions & 0 deletions src/templating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ fn get_tera() -> &'static Tera {

/// Render roles as HTML representation.
pub(crate) fn render_html(
title: String,
subtitle: Option<String>,
roles: Vec<Role>,
generated_at: DateTime<Utc>,
writer: impl Write,
) -> Result<()> {
let mut context = Context::new();
context.insert("roles", &roles);
context.insert("title", &title);
context.insert("subtitle", &subtitle);
context.insert("generated_at", &generated_at);

render("index.html", &context, writer)?;
Expand Down

0 comments on commit c85fe97

Please sign in to comment.