🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2022-07-06 13:12:12.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2022-07-06 13:12:12.0 +01:00:00
commit
8ecf34a1bdf85356a5e2da3cdc966339f6cb67b3 [patch]
tree
6ad9c3949c6e6f0fce1143546c4cbf843dd2eb8c
parent
5d9a1047578f33e71fc721b19382858813355693
download
8ecf34a1bdf85356a5e2da3cdc966339f6cb67b3.tar.gz

Use timeago to display age



Diff

 Cargo.lock               | 253 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 Cargo.toml               |   1 +
 src/git.rs               |  14 ++++++--------
 templates/index.html     |   4 +++-
 src/methods/filters.rs   |   3 +++
 src/methods/index.rs     |   1 +
 src/methods/mod.rs       |   1 +
 src/methods/repo.rs      |   1 +
 templates/repo/log.html  |   6 +++++-
 templates/repo/refs.html |  10 ++++++++--
 templates/repo/tag.html  |   2 +-
 11 files changed, 275 insertions(+), 21 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index a9eda85..1303f79 100644
--- a/Cargo.lock
+++ a/Cargo.lock
@@ -117,6 +117,15 @@

[[package]]
name = "autocfg"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78"
dependencies = [
 "autocfg 1.1.0",
]

[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
@@ -247,6 +256,19 @@
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
 "libc",
 "num-integer",
 "num-traits",
 "time 0.1.43",
 "winapi",
]

[[package]]
name = "clap"
@@ -271,6 +293,15 @@
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
dependencies = [
 "os_str_bytes",
]

[[package]]
name = "cloudabi"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
dependencies = [
 "bitflags",
]

[[package]]
@@ -298,7 +329,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace"
dependencies = [
 "autocfg",
 "autocfg 1.1.0",
 "cfg-if 0.1.10",
 "crossbeam-utils 0.7.2",
 "lazy_static",
@@ -313,7 +344,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
dependencies = [
 "autocfg",
 "autocfg 1.1.0",
 "cfg-if 0.1.10",
 "lazy_static",
]
@@ -367,6 +398,12 @@
 "matches",
 "percent-encoding",
]

[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"

[[package]]
name = "futures"
@@ -617,7 +654,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
dependencies = [
 "autocfg",
 "autocfg 1.1.0",
 "hashbrown",
]

@@ -628,6 +665,16 @@
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [
 "cfg-if 1.0.0",
]

[[package]]
name = "isolang"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "265ef164908329e47e753c769b14cbb27434abf0c41984dca201484022f09ce5"
dependencies = [
 "phf",
 "phf_codegen",
]

[[package]]
@@ -712,7 +759,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53"
dependencies = [
 "autocfg",
 "autocfg 1.1.0",
 "scopeguard",
]

@@ -770,7 +817,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa"
dependencies = [
 "autocfg",
 "autocfg 1.1.0",
]

[[package]]
@@ -840,6 +887,16 @@
dependencies = [
 "memchr",
 "minimal-lexical",
]

[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
 "autocfg 1.1.0",
 "num-traits",
]

[[package]]
@@ -848,7 +905,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
 "autocfg",
 "autocfg 1.1.0",
]

[[package]]
@@ -888,7 +945,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "835363342df5fba8354c5b453325b110ffd54044e588c539cf2f20a8014e4cb1"
dependencies = [
 "autocfg",
 "autocfg 1.1.0",
 "cc",
 "libc",
 "pkg-config",
@@ -943,6 +1000,44 @@
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"

[[package]]
name = "phf"
version = "0.7.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18"
dependencies = [
 "phf_shared",
]

[[package]]
name = "phf_codegen"
version = "0.7.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e"
dependencies = [
 "phf_generator",
 "phf_shared",
]

[[package]]
name = "phf_generator"
version = "0.7.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662"
dependencies = [
 "phf_shared",
 "rand",
]

[[package]]
name = "phf_shared"
version = "0.7.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0"
dependencies = [
 "siphasher",
]

[[package]]
name = "pin-project"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1036,15 +1131,130 @@
checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804"
dependencies = [
 "proc-macro2",
]

[[package]]
name = "rand"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
dependencies = [
 "autocfg 0.1.8",
 "libc",
 "rand_chacha",
 "rand_core 0.4.2",
 "rand_hc",
 "rand_isaac",
 "rand_jitter",
 "rand_os",
 "rand_pcg",
 "rand_xorshift",
 "winapi",
]

[[package]]
name = "rand_chacha"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
dependencies = [
 "autocfg 0.1.8",
 "rand_core 0.3.1",
]

[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
dependencies = [
 "rand_core 0.4.2",
]

[[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"

[[package]]
name = "rand_hc"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
dependencies = [
 "rand_core 0.3.1",
]

[[package]]
name = "rand_isaac"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
dependencies = [
 "rand_core 0.3.1",
]

[[package]]
name = "rand_jitter"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
dependencies = [
 "libc",
 "rand_core 0.4.2",
 "winapi",
]

[[package]]
name = "rand_os"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
dependencies = [
 "cloudabi",
 "fuchsia-cprng",
 "libc",
 "rand_core 0.4.2",
 "rdrand",
 "winapi",
]

[[package]]
name = "rand_pcg"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
dependencies = [
 "autocfg 0.1.8",
 "rand_core 0.4.2",
]

[[package]]
name = "rand_xorshift"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
dependencies = [
 "rand_core 0.3.1",
]

[[package]]
name = "raw-cpuid"
version = "10.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "738bc47119e3eeccc7e94c4a506901aea5e7b4944ecd0829cbebf4af04ceda12"
dependencies = [
 "bitflags",
]

[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
dependencies = [
 "rand_core 0.3.1",
]

[[package]]
@@ -1081,7 +1291,8 @@
 "moka",
 "path-clean",
 "serde",
 "time",
 "time 0.3.11",
 "timeago",
 "tokio",
 "tower",
 "tower-layer",
@@ -1192,6 +1403,12 @@
]

[[package]]
name = "siphasher"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac"

[[package]]
name = "skeptic"
version = "0.13.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1313,6 +1530,16 @@
checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180"
dependencies = [
 "once_cell",
]

[[package]]
name = "time"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
dependencies = [
 "libc",
 "winapi",
]

[[package]]
@@ -1323,6 +1550,16 @@
dependencies = [
 "libc",
 "num_threads",
]

[[package]]
name = "timeago"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ec32dde57efb15c035ac074118d7f32820451395f28cb0524a01d4e94983b26"
dependencies = [
 "chrono",
 "isolang",
]

[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 9cc8330..acd49b9 100644
--- a/Cargo.toml
+++ a/Cargo.toml
@@ -19,6 +19,7 @@
path-clean = "0.1"
serde = { version = "1.0", features = ["derive"] }
time = "0.3"
timeago = "0.3"
tokio = { version = "1.19", features = ["full"] }
tower = "0.4"
tower-service = "0.3"
diff --git a/src/git.rs b/src/git.rs
index f025d13..47df5b5 100644
--- a/src/git.rs
+++ a/src/git.rs
@@ -267,7 +267,7 @@
    pub name: String,
    pub description: Option<Cow<'static, str>>,
    pub owner: Option<String>,
    pub last_modified: Duration,
    pub last_modified: OffsetDateTime,
}

#[derive(Debug)]
@@ -275,7 +275,7 @@
    name: String,
    email: String,
    email_md5: String,
    time: String,
    time: OffsetDateTime,
}

impl From<Signature<'_>> for CommitUser {
@@ -285,8 +285,7 @@
            email: v.email().unwrap().to_string(),
            email_md5: format!("{:x}", md5::compute(v.email_bytes())),
            time: OffsetDateTime::from_unix_timestamp(v.when().seconds())
                .unwrap()
                .to_string(),
                .unwrap(),
        }
    }
}
@@ -304,8 +303,8 @@
        &self.email_md5
    }

    pub fn time(&self) -> &str {
        &self.time
    pub fn time(&self) -> OffsetDateTime {
        self.time
    }
}

@@ -409,8 +408,7 @@
                .into_owned(),
            description,
            owner,
            last_modified: (OffsetDateTime::now_utc() - OffsetDateTime::from(last_modified))
                .unsigned_abs(),
            last_modified: OffsetDateTime::from(last_modified),
        });
    }
}
diff --git a/templates/index.html b/templates/index.html
index 6fdaf58..2a8b07d 100644
--- a/templates/index.html
+++ a/templates/index.html
@@ -44,7 +44,9 @@
                    </td>
                    <td>
                        <a href="/{% if let Some(path) = path %}{{ path }}/{% endif %}{{ repository.name }}">
                            {{ humantime::format_duration(repository.last_modified.clone()) }}
                            <time datetime="{{ repository.last_modified }}" title="{{ repository.last_modified }}">
                                {{ repository.last_modified.clone()|timeago }}
                            </time>
                        </a>
                    </td>
                </tr>
diff --git a/src/methods/filters.rs b/src/methods/filters.rs
new file mode 100644
index 0000000..286009f 100644
--- /dev/null
+++ a/src/methods/filters.rs
@@ -1,0 +1,3 @@
pub fn timeago(s: time::OffsetDateTime) -> Result<String, askama::Error> {
    Ok(timeago::Formatter::new().convert((time::OffsetDateTime::now_utc() - s).unsigned_abs()))
}
diff --git a/src/methods/index.rs b/src/methods/index.rs
index 6575bdc..7711e4f 100644
--- a/src/methods/index.rs
+++ a/src/methods/index.rs
@@ -1,8 +1,9 @@
use askama::Template;
use axum::response::Html;
use axum::Extension;
use std::sync::Arc;

use super::filters;
use crate::{git::RepositoryMetadataList, Git};

#[allow(clippy::unused_async)]
diff --git a/src/methods/mod.rs b/src/methods/mod.rs
index 5592c5f..515ab4b 100644
--- a/src/methods/mod.rs
+++ a/src/methods/mod.rs
@@ -1,2 +1,3 @@
pub mod index;
pub mod repo;
pub mod filters;
diff --git a/src/methods/repo.rs b/src/methods/repo.rs
index 8dd6269..a1d583c 100644
--- a/src/methods/repo.rs
+++ a/src/methods/repo.rs
@@ -16,6 +16,7 @@
use serde::Deserialize;
use tower::{util::BoxCloneService, Service};

use super::filters;
use crate::git::{DetailedTag, Refs};
use crate::{git::Commit, layers::UnwrapInfallible, Git};

diff --git a/templates/repo/log.html b/templates/repo/log.html
index 1f06e7d..f73e143 100644
--- a/templates/repo/log.html
+++ a/templates/repo/log.html
@@ -15,7 +15,11 @@
    <tbody>
    {% for commit in commits %}
    <tr>
        <td>{{ commit.committer().time() }}</td>
        <td>
            <time datetime="{{ commit.committer().time() }}" title="{{ commit.committer().time() }}">
                {{ commit.committer().time()|timeago }}
            </time>
        </td>
        <td><a href="/{{ repo.display() }}/commit/?id={{ commit.oid() }}">{{ commit.summary() }}</a></td>
        <td>
            <img src="https://www.gravatar.com/avatar/{{ commit.author().email_md5() }}?s=13&d=retro" width="13" height="13">
diff --git a/templates/repo/refs.html b/templates/repo/refs.html
index 6ab2718..0c7adb4 100644
--- a/templates/repo/refs.html
+++ a/templates/repo/refs.html
@@ -22,7 +22,11 @@
            <img src="https://www.gravatar.com/avatar/{{ branch.commit.author().email_md5() }}?s=13&d=retro" width="13" height="13">
            {{ branch.commit.author().name() }}
        </td>
        <td>{{ branch.commit.author().time() }}</td>
        <td>
            <time datetime="{{ branch.commit.author().time() }}" title="{{ branch.commit.author().time() }}">
                {{ branch.commit.author().time()|timeago }}
            </time>
        </td>
    </tr>
    {% endfor %}
    </tbody>
@@ -54,7 +58,9 @@
        </td>
        <td>
            {% if let Some(tagger) = tag.tagger %}
                {{ tagger.time() }}
                <time datetime="{{ tagger.time() }}" title="{{ tagger.time() }}">
                    {{ tagger.time()|timeago }}
                </time>
            {% endif %}
        </td>
    </tr>
diff --git a/templates/repo/tag.html b/templates/repo/tag.html
index 09bd4bb..e00abfa 100644
--- a/templates/repo/tag.html
+++ a/templates/repo/tag.html
@@ -23,7 +23,7 @@
            <td>
                {% match tagged_object %}
                    {% when crate::git::TaggedObject::Commit with (commit) %}
                        <a href="/{{ repo.display() }}/commit?id={{ commit }}">commit {{ commit.as_str()[0..10] }}...</a>
                        <a href="/{{ repo.display() }}/commit?id={{ commit }}">commit {{ commit|truncate(10) }}...</a>
                    {% when crate::git::TaggedObject::Tree with (tree) %}
                        tree {{ tree }}
                {% endmatch %}