forked from ivansaul/personal-portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
101 lines (79 loc) · 2.92 KB
/
main.py
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
from datetime import datetime
import toml # type: ignore
from jinja2 import Environment, FileSystemLoader # type: ignore
class Portfolio:
def __init__(self):
self.about_toml = "config/about.toml"
self.social_toml = "config/social.toml"
self.doing_toml = "config/doing.toml"
self.softskills_toml = "config/softskills.toml"
self.technologies_toml = "config/technologies.toml"
self.resume_toml = "config/resume.toml"
self.projects_toml = "config/projects.toml"
self.blog_toml = "config/blog.toml"
def read_file(self, file_path):
with open(file_path, "r", encoding="utf-8") as file:
content = file.read()
return content
def write_file(self, file_path, content):
with open(file_path, "w", encoding="utf-8") as file:
file.write(content)
def load_toml_file(self, file_path):
with open(file_path, "r", encoding="utf-8") as file:
content = file.read()
data = toml.loads(content)
return data
def format_date(self, date: str):
date_object = datetime.strptime(date, "%Y-%m-%d")
formatted_date = date_object.strftime("%b %d, %Y")
return formatted_date
def about(self):
return self.load_toml_file(self.about_toml)
def social(self):
return self.load_toml_file(self.social_toml)
def doing(self):
return self.load_toml_file(self.doing_toml)["doing"]
def softskills(self):
return self.load_toml_file(self.softskills_toml)
def technologies(self):
data = self.load_toml_file(self.technologies_toml)
return data
def resume(self):
toml_cfg = self.load_toml_file(self.resume_toml)
return toml_cfg
def projects(self):
return self.load_toml_file(self.projects_toml)
def blog(self):
return self.load_toml_file(self.blog_toml)
def categories(self):
filters = []
projects = self.projects()["project"]
for project in projects:
filters.append(project["category"])
return set(filters)
if __name__ == "__main__":
portfolio = Portfolio()
about = portfolio.about()
doing = portfolio.doing()
social = portfolio.social()
softskills = portfolio.softskills()
technologies = portfolio.technologies()
resume = portfolio.resume()
projects = portfolio.projects()
blog = portfolio.blog()
categories = portfolio.categories()
env = Environment(loader=FileSystemLoader("src/jinja"))
env.filters["format_date"] = portfolio.format_date
template = env.get_template("index.jinja")
html_render = template.render(
about=about,
social=social,
doing=doing,
softskills=softskills,
technologies=technologies,
resume=resume,
projects=projects,
blog=blog,
categories=categories,
)
portfolio.write_file("index.html", html_render)