index : sparkle-git.git

ascending towards madness

author holly sparkles <sparkles@holly.sh> 2023-12-24 15:02:39.0 +00:00:00
committer holly sparkles <sparkles@holly.sh> 2024-05-14 6:40:47.0 +00:00:00
commit
97acdfc01b43c4a016eee537b01fda7c956093fe [patch]
tree
a04f234dadd61348a4401033c1fc8fa3aebb607b
parent
2b9f2bd95fe78f74172cf29be4d495cf881703b8
download
97acdfc01b43c4a016eee537b01fda7c956093fe.tar.gz

feat: add truncating repo description and commit messages in lists

- max_commit_message_length
- max_repo_desc_length

Diff

 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 @@
                <td>
                    <a href="/{% if let Some(path) = path %}{{ path }}/{% endif %}{{ repository.name }}">
                        {%- 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 -}}
            </time>
        </td>
        <td><a href="/{{ repo.display() }}/commit/?id={{ commit.hash|hex }}">{{ commit.summary }}</a></td>
        <td>
			<a href="/{{ repo.display() }}/commit/?id={{ commit.hash|hex }}">
				{% if config.max_commit_message_length.clone() > 0 %}
				{{ commit.summary|truncate(config.max_commit_message_length.clone()) }}
				{% else %}
				{{ commit.summary }}
				{% endif %}
			</a>
		</td>
        <td>
            <img src="https://www.gravatar.com/avatar/{{ commit.author.email|md5 }}?s=13&d=retro" width="13" height="13">
            {{ commit.author.name }}