improve publications section

This commit is contained in:
Sina Atalay 2023-10-01 21:43:28 +02:00
parent 0107906480
commit a0c8cb254b
5 changed files with 83 additions and 7 deletions

View File

@ -592,6 +592,23 @@ class Event(BaseModel):
return markdown_url
@computed_field
@cached_property
def month_and_year(self) -> Optional[str]:
if self.date is not None:
# Then it means start_date and end_date are not provided.
try:
# If this runs, it means the date is an ISO format string, and it can be
# parsed
month_and_year = format_date(Date.fromisoformat(self.date))
except:
month_and_year = self.date
else:
# Then it means start_date and end_date are provided and month_and_year
# doesn't make sense.
month_and_year = None
return month_and_year
class OneLineEntry(Event):
"""This class stores [OneLineEntry](../index.md#onelineentry) information."""

View File

@ -126,6 +126,65 @@ def make_it_bold(value: str, match_str: str) -> str:
else:
return value
def make_it_underlined(value: str, match_str: str) -> str:
"""Make the matched parts of the string underlined.
This function is used as a Jinja2 filter.
Example:
```python
make_it_underlined_if("Hello World!", "Hello")
```
will return:
`#!python "\\underline{Hello} World!"`
Args:
value (str): The string to make underlined.
match_str (str): The string to match.
"""
if not isinstance(value, str):
raise ValueError("make_it_underlined_if should only be used on strings!")
if not isinstance(match_str, str):
raise ValueError("The string to match should be a string!")
if match_str in value:
value = value.replace(match_str, "\\underline{" + match_str + "}")
return value
else:
return value
def make_it_italic(value: str, match_str: str) -> str:
"""Make the matched parts of the string italic.
This function is used as a Jinja2 filter.
Example:
```python
make_it_italic_if("Hello World!", "Hello")
```
will return:
`#!python "\\textit{Hello} World!"`
Args:
value (str): The string to make italic.
match_str (str): The string to match.
"""
if not isinstance(value, str):
raise ValueError("make_it_italic_if should only be used on strings!")
if not isinstance(match_str, str):
raise ValueError("The string to match should be a string!")
if match_str in value:
value = value.replace(match_str, "\\textit{" + match_str + "}")
return value
else:
return value
def render_template(data):
"""Render the template using the given data.
@ -164,6 +223,8 @@ def render_template(data):
environment.filters["markdown_to_latex"] = markdown_to_latex
environment.filters["markdown_url_to_url"] = markdown_url_to_url
environment.filters["make_it_bold"] = make_it_bold
environment.filters["make_it_underlined"] = make_it_underlined
environment.filters["make_it_italic"] = make_it_italic
output_latex_file = template.render(design=data.design.options, cv=data.cv)

View File

@ -11,7 +11,7 @@
bottom=<<design.margins.page.bottom>>, % seperation between body and page edge from the bottom
left=<<design.margins.page.left>>, % seperation between body and page edge from the left
right=<<design.margins.page.right>>, % seperation between body and page edge from the right
showframe % for debugging
% showframe % for debugging
]{geometry} % for adjusting page geometry
\usepackage{fontspec} % for loading fonts
\usepackage[explicit]{titlesec} % for customizing section titles

View File

@ -55,7 +55,7 @@
\end{tabularx}
((* endmacro *))
((* macro publication(title, authors, journal, year, doi, doi_url)*))
((* macro publication(title, authors, journal, date, doi, doi_url)*))
((# \begin{tabularx}{⟨width⟩}[⟨pos⟩]{⟨preamble⟩} #))
((# width: \textwidth #))
((# preamble: first column, second column #))
@ -64,13 +64,11 @@
\begin{tabularx}{\textwidth}{K{<<design.margins.entry_area.left>>} R{2 cm}}
\textbf{<<title>>}
<<authors|join(", ")|make_it_bold("Cetin Yilmaz")>>
<<authors|join(", ")|make_it_italic(cv.name)>>
DOI: \hrefExternal{<<doi_url>>}{<<doi>>}
<<journal>>
&
<<year>>
<<date>>
\end{tabularx}
((* endmacro *))

View File

@ -41,7 +41,7 @@
title=value.title,
authors=value.authors,
journal=value.journal,
year=value.date,
date=value.month_and_year,
doi=value.doi,
doi_url=value.doi_url,
)|indent(4)>>