~homeworkprod/orgatalk-discord-orgateams

c85fe973b72f9062f4dae985a64d0a7bb7d1c24d — Jochen Kupperschmidt 2 months ago d63f08c
Make title, subtitle configurable
6 files changed, 19 insertions(+), 4 deletions(-)

M CHANGELOG.md
M config-example.toml
M src/config.rs
M src/main.rs
M src/templates/index.html
M src/templating.rs
M CHANGELOG.md => CHANGELOG.md +2 -0
@@ 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.

M config-example.toml => config-example.toml +3 -0
@@ 1,3 1,6 @@
title = "Title"
subtitle = "Subtitle"

[discord]
bot_token = "your-secret-bot-token"
guild_id = "your-guild-id"

M src/config.rs => src/config.rs +2 -0
@@ 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,
}


M src/main.rs => src/main.rs +3 -1
@@ 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)?,
    };

M src/templates/index.html => src/templates/index.html +5 -3
@@ 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;


@@ 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>


M src/templating.rs => src/templating.rs +4 -0
@@ 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)?;