Text this: Fermat's principle in general relativity via Herglotz variational formalism