\usepackage[ignoreheadfoot, top=\PageYMargin, bottom=\PageYMargin, left=\PageXMargin, right=\PageXMargin, headsep=0.3cm]{geometry}
\usepackage{fontspec}
\usepackage[explicit]{titlesec}
\usepackage{tabularx}
\usepackage{array}
\usepackage{xifthen}
\usepackage[dvipsnames]{xcolor}
\definecolor{primaryColor}{RGB}{\PRIMARYCOLOR}
\usepackage{enumitem}
\usepackage{fontawesome}
\usepackage[pdftitle={\AUTHOR's CV}, pdfauthor={\AUTHOR}, colorlinks=true, urlcolor=primaryColor]{hyperref} % Linking

% \setmainfont{SourceSansPro}[
%     Path= fonts/,
%     Extension = .ttf,
%     UprightFont = *-Regular,
%     ItalicFont = *-Italic,
%     BoldFont = *-Bold,
%     BoldItalicFont = *-BoldItalic]

% Calculate last update top margin:
\newlength\A
\newlength\B
\setlength\A{\PageYMargin}
\setlength\B{\dimexpr \numexpr \A / 1 \relax sp\relax}

\setcounter{secnumdepth}{0} % No section numbering
\setlength{\parindent}{0pt} % No indentation
\setlength{\topskip}{0pt} % No top skip
\pagenumbering{gobble} % No page numbering

\titleformat{\section}{\LARGE\color{primaryColor}}{}{}{\textbf{#1}\hspace{0.15cm}\titlerule[0.8pt]}[] % New section title format
\titlespacing{\section}{0pt}{\TopMarginOfSections}{\BottomMarginOfSections} % New section title spacing

% Date format (from: https://web.library.yale.edu/cataloging/months):
% \makeatletter
% \def\month@english{\ifcase\month\or
%         Jan.\or Feb.\or Mar.\or Apr.\or May\or June\or
%         July\or Aug.\or Sept.\or Oct.\or Nov.\or Dec.\fi}
% \makeatother
% \origdate

% New column types:
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}

% New commands/environments:
\newenvironment{highlights}{\begin{itemize}[topsep=0pt, parsep=\YMarginBetweenBullets, partopsep=0pt, itemsep=0pt, after=\vspace*{-\baselineskip}, leftmargin=\LeftMarginOfBullets]}{\end{itemize}} % New environment for highlights

\newenvironment{header}[1][\topsep]{\setlength{\topsep}{#1}\par\kern\topsep\centering\color{primaryColor}\linespread{1.5}}{\par\kern\topsep} % New environment for the header

% New commands:
\newcommand{\hrefExternal}[2]{\href{#1}{#2\, \faExternalLink}}

\newcommand{\Header}[6]{
    \begin{header}[0pt]
        \Huge
        \textbf{#1}

        \normalsize
        \faPhone\hspace{0.13cm}#2 \hspace{0.5cm}
        \href{mailto:#3}{\faEnvelopeO\hspace{0.13cm}#3} \hspace{0.5cm}
        \href{https://#4}{\faLaptop\hspace{0.13cm}#4} \hspace{0.5cm}
        \href{https://www.linkedin.com/in/#5}{\faLinkedin\hspace{0.13cm}#5} \hspace{0.5cm}
        \href{https://www.github.com/#6}{\faGithub\hspace{0.13cm}#6}
    \end{header}
}

\newcommand{\EducationEntry}[8]{
    \begin{tabularx}{\textwidth}{p{0.55cm} >{\raggedright}X R{\DateandLocationWidth}}
        \textbf{#1} & \textbf{#2}, #3 \ifthenelse{\isempty{#6}}{}{\vspace{\YMarginBetweenBullets}\begin{highlights} \item #6 \ifthenelse{\isempty{#7}}{\end{highlights}}{\item #7 \ifthenelse{\isempty{#8}}{\end{highlights}}{\item #8 \end{highlights}}}} & \ifthenelse{\isempty{#4}}{#5}{#4\newline #5} \\
    \end{tabularx}

    \vspace{\YMarginBetweenEntries}
}

\newcommand{\ExperienceEntry}[8]{
    \begin{tabularx}{\textwidth}{X R{\DateandLocationWidth}}
        \textbf{#1}, #2 \ifthenelse{\isempty{#6}}{}{\vspace{\YMarginBetweenBullets}\begin{highlights} \item #6 \ifthenelse{\isempty{#7}}{\end{highlights}}{\item #7 \ifthenelse{\isempty{#8}}{\end{highlights}}{\item #8 \end{highlights}}}} & \ifthenelse{\isempty{#3}}{#4\newline #5}{#3\newline #4\newline #5} \\
    \end{tabularx}

    \vspace{\YMarginBetweenEntries}
}

\newcommand{\NormalEntry}[6]{
    \begin{tabularx}{\textwidth}{X R{\DateandLocationWidth}}
        \textbf{#1} \ifthenelse{\isempty{#4}}{}{\vspace{\YMarginBetweenBullets}\begin{highlights} \item #4 \ifthenelse{\isempty{#5}}{\end{highlights}}{\item #5 \ifthenelse{\isempty{#6}}{\end{highlights}}{\item #6 \end{highlights}}}} & \ifthenelse{\isempty{#2}}{#3}{#2\newline #3} \\
    \end{tabularx}

    \vspace{\YMarginBetweenEntries}
}

\newcommand{\OneLineEntry}[2]{
    \setlength{\leftskip}{0.2cm}
    \textbf{#1:} #2

    \vspace{\YMarginBetweenEntries}
    \setlength{\leftskip}{0cm}
}