Pi66

git.pi66.xyz
A web interface for the pi66.xyz Git server
git clone https://git.pi66.xyz/git.pi66.xyz

← back to log

feat: show repo last commit date as relative time (like 3 days ago)

author: pi66
date: 2026-07-23 16:19
hash: 0052d143fbe297c0d1f91a27df1209108fa3929d

Diffstat:

M

src/plugins/main.py
2 -

M

src/templates/partials/scripts.html
82 ++++++++++++++++++++----------
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
diff --git a/src/plugins/main.py b/src/plugins/main.py
index adab8eb..1663b37 100644
--- a/src/plugins/main.py
+++ b/src/plugins/main.py
@@ -40,7 +40,7 @@ def inject_repos(md_file, md_content):
             f'    <td> <a href="/{repo.name.lower()}/log.html"><strong>{repo.name}</strong></a> </td>\n'
             f'    <td class="!text-gray-400"> {repo.desc}</td>\n'
             f'    <td class="!text-gray-400"> {repo.author}</td>\n'
-            f'    <td class="!text-gray-400"> {repo.last_commit_date}</td>\n'
+            f'    <td class="!text-gray-400 time-ago"> {repo.last_commit_date}</td>\n'
             f'</tr>'
         )
     table = "\n\n".join(rows)
diff --git a/src/templates/partials/scripts.html b/src/templates/partials/scripts.html
index 063f61e..bcfda13 100644
--- a/src/templates/partials/scripts.html
+++ b/src/templates/partials/scripts.html
@@ -1,28 +1,56 @@
 <script>
-        function typePerLetter(selector, speed = 100) {
-            const el = document.querySelector(selector);
-            if (!el) return;
-
-            const text = el.textContent;
-            el.textContent = "";
-            let i = 0;
-
-            const interval = setInterval(() => {
-                if (i >= text.length) {
-                    clearInterval(interval);
-                    return;
-                }
-
-                const char = text[i];
-                if (char === "\n") {
-                    el.appendChild(document.createElement("br"));
-                } else {
-                    el.append(char);
-                }
-                i++;
-            }, speed);
-        }
-
-        typePerLetter(".pi66-title", 120);
-        document.body.style.zoom = "100%";
-    </script>
\ No newline at end of file
+function timeAgo(dateString) {
+   const date = new Date(dateString.replace(" ", "T"));
+   const now = new Date();
+   const diff = now - date;
+
+   const units = [
+       ["year", 365 * 24 * 60 * 60 * 1000],
+       ["month", 30 * 24 * 60 * 60 * 1000],
+       ["day", 24 * 60 * 60 * 1000],
+       ["hour", 60 * 60 * 1000],
+       ["minute", 60 * 1000],
+       ["second", 1000],
+   ];
+
+   for (const [unit, ms] of units) {
+       const value = Math.floor(diff / ms);
+
+       if (value >= 1) {
+           return `<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mrow><mi>v</mi><mi>a</mi><mi>l</mi><mi>u</mi><mi>e</mi></mrow></mrow></math>{unit}${value !== 1 ? "s" : ""} ago`;
+       }
+   }
+
+   return "just now";
+}
+
+   function typePerLetter(selector, speed = 100) {
+       const el = document.querySelector(selector);
+       if (!el) return;
+
+       const text = el.textContent;
+       el.textContent = "";
+       let i = 0;
+
+       const interval = setInterval(() => {
+           if (i >= text.length) {
+               clearInterval(interval);
+               return;
+           }
+
+           const char = text[i];
+           if (char === "\n") {
+               el.appendChild(document.createElement("br"));
+           } else {
+               el.append(char);
+           }
+           i++;
+       }, speed);
+   }
+
+   typePerLetter(".pi66-title", 120);
+   document.body.style.zoom = "100%";
+   document.querySelectorAll(".time-ago").forEach(element => {
+       element.textContent = timeAgo(element.textContent.trim());
+   });
+</script>