On 08/01/2017 08:04 PM, Gordon Fontenot wrote:
> I'd like to tell Hakyll to display posts in my 'drafts' folder when
> running the `watch` command. However, I _don't_ want to add explicit
> dates to those drafts. So I'd like to tell Hakyll that it should use
> today's date if it's unable to parse a date from the file using
> `dateField`.
Perhaps something like this would do:
let ctx = dateField "date" "%F" `mappend`
modificationTimeField "date" "%F" `mappend`
defaultContext
pandocCompiler >>= loadAndApplyTemplate ctx "template/..."
When this context is asked to produce a "date" value, it will try
dateField first, and if that fails, it should fall through to
modificationTimeField, which uses the last-modified date on the
underlying file.
Alternatively, we could replace `modificationTimeField` with any other
context that includes a "date" field, such as
constField "date" "January 1st, 1970"
If we *really* wanted "today's date", we could construct a `buildDate`
field using `field`, `unsafeCompiler`, `getCurrentTime`, and `formatTime
(the latter two from `Data.Time`). But I suspect that one of
modificationTimeField or constField would be close enough. :)
HTH,
Daniel