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>