[Tex/LaTex] Moderncv shorthand URL in header

hyperreflinksmoderncv

I'm using moderncv to write my CV and I'd like to use a shorthand link in the header of my CV. The command \httplink has an optional argument to do this, but this argument is not passed to \homepage.

How can I redefine \homepage to pass the shorthand link as an optional argument to \httplink in the \maketitle command without messing everything up?

An example of what I was thinking of is

\documentclass[11pt,a4paper,sans]{moderncv}

\moderncvstyle{classic}
\moderncvcolor{blue}

\renewcommand*{\homepage}[2]{\def\@homepage[#1]{#2}}

\firstname{John}
\lastname{Doe}

\homepage[shorthand]{long link that I'd like to mask}

\begin{document}

\maketitle

\end{document}

Except that I don't if that is the proper way to redefine homepage and this code doesn't redefine line 265 of moderncvclassic.sty where, as far as I can tell the argument of homepage is passed to httplink.

Best Answer

You'll have to patch \makecvtitle after loading the classic style using something like etoolbox.

I've done so below, replacing the \httplink{\@homepage} piece with a conditional based on whether you supplied a shorthand argument <desc> or not through the updated \homepage[<desc>]{<URL>}:

enter image description here

\documentclass{moderncv}

\moderncvstyle{classic}
\moderncvcolor{blue}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\makecvtitle}% <cmd>
  {\httplink{\@homepage}}% <search>
  {{\ifx\@homepage@shorthand\relax
     \httplink{\@homepage}% Used \homepage{<URL>}
   \else
     \httplink[\@homepage@shorthand]{\@homepage}% Used \homepage[<desc>]{<URL>}
   \fi}}% <replace>
  {}{}% <succes><failure>

\RenewDocumentCommand{\homepage}{o m}{%
  \let\@homepage@shorthand\relax%
  \providecommand\@homepage{#2}%
  \IfNoValueF{#1}{\def\@homepage@shorthand{#1}}%
}
\makeatother

\firstname{John}
\lastname{Doe}

\homepage[shorthand]{long link that I'd like to mask}

\begin{document}

\maketitle

\end{document}