Skip to content

Commit 2a221e8

Browse files
committed
feat: massive improvements
1 parent 222e195 commit 2a221e8

5 files changed

Lines changed: 889 additions & 279 deletions

File tree

generator.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import datetime
34
import json
45
import re
56
from pathlib import Path
@@ -89,6 +90,47 @@ def render_experience_item(item: dict[str, Any]) -> str:
8990
return render_template("partials/experience_item.html", {"item": context_item})
9091

9192

93+
def calculate_duration(start_val: Any) -> str:
94+
if not start_val:
95+
return ""
96+
97+
today = datetime.date.today()
98+
try:
99+
if isinstance(start_val, int):
100+
start_year = start_val
101+
start_month = 1
102+
start_day = 1
103+
elif isinstance(start_val, str):
104+
parts = [int(p) for p in start_val.split("-") if p.isdigit()]
105+
if len(parts) == 3:
106+
start_year, start_month, start_day = parts
107+
elif len(parts) == 2:
108+
start_year, start_month = parts
109+
start_day = 1
110+
elif len(parts) == 1:
111+
start_year = parts[0]
112+
start_month = 1
113+
start_day = 1
114+
else:
115+
return str(start_val)
116+
else:
117+
return str(start_val)
118+
119+
years = today.year - start_year - ((today.month, today.day) < (start_month, start_day))
120+
121+
if years <= 0:
122+
months = (today.year - start_year) * 12 + today.month - start_month
123+
if months <= 1:
124+
return "1 month"
125+
return f"{months} months"
126+
elif years == 1:
127+
return "over 1 year"
128+
else:
129+
return f"over {years} years"
130+
except Exception:
131+
return str(start_val)
132+
133+
92134
def render_skill_item(skill: dict[str, Any], project_ids: dict[str, str]) -> str:
93135
skill_id = slugify(skill["name"].replace("/", "-").replace("+", "plus"))
94136

@@ -113,8 +155,12 @@ def render_skill_item(skill: dict[str, Any], project_ids: dict[str, str]) -> str
113155
icon_html = f'<ion-icon name="{skill["icon"]}" class="text-lg mr-2"></ion-icon>'
114156

115157
duration_html = ""
116-
if skill.get("duration"):
117-
duration_html = f'<span class="text-xs font-mono text-zinc-500 dark:text-zinc-400">{skill["duration"]}</span>'
158+
duration = skill.get("duration")
159+
if skill.get("start_date"):
160+
duration = calculate_duration(skill["start_date"])
161+
162+
if duration:
163+
duration_html = f'<span class="text-xs font-mono text-zinc-500 dark:text-zinc-400">{duration}</span>'
118164

119165
details_html = ""
120166
if skill.get("details"):

0 commit comments

Comments
 (0)