From 97acdfc01b43c4a016eee537b01fda7c956093fe Mon Sep 17 00:00:00 2001 From: holly sparkles Date: Sun, 24 Dec 2023 16:02:39 +0100 Subject: [PATCH] feat: add truncating repo description and commit messages in lists - max_commit_message_length - max_repo_desc_length --- rgit.conf.example | 6 +++++- src/configuration/mod.rs | 16 ++++++++++++++++ templates/index.html | 6 +++++- templates/repo/macros/refs.html | 10 +++++++++- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/rgit.conf.example b/rgit.conf.example index 575dfb9..a11bccd 100644 --- a/rgit.conf.example +++ b/rgit.conf.example @@ -27,4 +27,8 @@ enable_index_owner = true # Generate HTTPS clone urls clone_prefix = 'https://git.mydomain.tld' # Generate SSH clone urls -ssh_clone_prefix = 'ssh://git.mydomain.tld:/srv/git' \ No newline at end of file +ssh_clone_prefix = 'ssh://git.mydomain.tld:/srv/git' +# Limit length of commit messages in the log to this; use 0 for no limit +max_commit_message_length = 80 +# Limit length of repository descriptions; use 0 for no limit +max_repo_desc_length = 80 \ No newline at end of file diff --git a/src/configuration/mod.rs b/src/configuration/mod.rs index 17b84cc..2b2a60b 100644 --- a/src/configuration/mod.rs +++ b/src/configuration/mod.rs @@ -72,6 +72,20 @@ pub struct AppConfig { /// /// Default value: `unset` pub ssh_clone_prefix: String, + + /// Specifies the maximum number of commit message characters to display in "log" view. + /// + /// A value of "0" indicates no limit. + /// + /// Default value: "0" + pub max_commit_message_length: usize, + + /// Specifies the maximum number of description characters to display on the repository index page. + /// + /// A value of "0" indicates no limit. + /// + /// Default value: "0" + pub max_repo_desc_length: usize, } impl ::std::default::Default for AppConfig { @@ -94,6 +108,8 @@ impl ::std::default::Default for AppConfig { enable_index_owner: true, clone_prefix: String::new(), ssh_clone_prefix: String::new(), + max_commit_message_length: 0, + max_repo_desc_length: 0, } } } diff --git a/templates/index.html b/templates/index.html index 285fc85..1b278ee 100644 --- a/templates/index.html +++ b/templates/index.html @@ -34,7 +34,11 @@ {%- if let Some(description) = repository.description -%} - {{- description -}} + {% if config.max_repo_desc_length > 0 %} + {{- description|truncate(config.max_repo_desc_length.clone()) -}} + {% else %} + {{- description -}} + {% endif %} {%- else -%} Unnamed repository; edit this file 'description' to name the repository. {%- endif -%} diff --git a/templates/repo/macros/refs.html b/templates/repo/macros/refs.html index 51128da..1cf6a85 100644 --- a/templates/repo/macros/refs.html +++ b/templates/repo/macros/refs.html @@ -78,7 +78,15 @@ {{- commit.committer.time.clone()|timeago -}} - {{ commit.summary }} + + + {% if config.max_commit_message_length.clone() > 0 %} + {{ commit.summary|truncate(config.max_commit_message_length.clone()) }} + {% else %} + {{ commit.summary }} + {% endif %} + + {{ commit.author.name }} -- libgit2 1.7.2