Discussion:
[hakyll] Easy way to add an updated date field
Deepak Jois
2016-08-31 14:48:00 UTC
Permalink
Hi

In addition to the ‘published’ date, I want to track an ‘updated’
field in my YAML frontmatter which denotes the date a post was
updated.

After looking around, the best I could come up with was this:
https://github.com/deepakjois/website/commit/2d23f9d47e927f58fd450a327e6907ef1b0b2b64

It is essentially code lifted from the core Hakyll codebase with
function names and a string value (published -> updated) changed.

Is there a better way to do this? Can the Hakyll API provide a way to
specify additional date fields in the YAML front matter easily?

Thanks
Deepak
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Gwern Branwen
2016-08-31 15:55:41 UTC
Permalink
Post by Deepak Jois
Is there a better way to do this? Can the Hakyll API provide a way to
specify additional date fields in the YAML front matter easily?
Isn't this already covered by 'modificationTimeField'?
--
gwern
http://www.gwern.net
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Deepak Jois
2016-08-31 16:16:23 UTC
Permalink
Post by Gwern Branwen
Post by Deepak Jois
Is there a better way to do this? Can the Hakyll API provide a way to
specify additional date fields in the YAML front matter easily?
Isn't this already covered by 'modificationTimeField'?
Not really. modificationTimeField seems to work with modification
times of files on a filesystem. This may not work, say if I clone my
site’s git repo on another machine. I will lose the info of when the
post was last updated.

What I am looking for is to explicitly track a date value (under a key
like ‘updated’ or ‘lastupdated’ or whatever) in the post metadata,
which I can then format and display.

Deepak
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Gwern Branwen
2017-03-12 03:33:22 UTC
Permalink
Post by Deepak Jois
What I am looking for is to explicitly track a date value (under a key
like ‘updated’ or ‘lastupdated’ or whatever) in the post metadata,
which I can then format and display.
I see. In that case, maybe you could do something with filestore? I assume
you version-control your site, so you could use filestore to extract the
date of the last patch modifying each particular file and store that as a
variable and then transclude it.

Another method might be editor-based. It would be maddeningly tedious to
update afield yourself but it is possible to script an editor to
automatically update a particular line in a file. For example, in Emacs:
https://www.gnu.org/software/emacs/manual/html_node/emacs/Time-Stamps.html#Time-Stamps
The default format there might not be YAML compatible but you can probably
come up with one which is.
--
gwern
https://www.gwern.net
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jasper Van der Jeugt
2017-03-14 12:01:23 UTC
Permalink
It depends on what you want to do. If you only want to format and
display this value, it's easy:

1. Add an "updated: 2017-03-14" field to all your posts.
2. Add a field to your context which parses and formats this value:

field "updated" (\item -> do
mbUpdated <- getMetadataField (itemIdentifier item) "updated"
maybe empty return $ do
updated <- mbUpdated
time <- parseTime defaultTimeLocale "%Y-%m-%d" updated
:: Maybe UTCTime
return $ formatTime defaultTimeLocale "%B %e, %Y" time)

3. Use the `$updated$` key in your templates.

Hope this helps,
Jasper
Post by Gwern Branwen
Post by Deepak Jois
What I am looking for is to explicitly track a date value (under a key
like ‘updated’ or ‘lastupdated’ or whatever) in the post metadata,
which I can then format and display.
I see. In that case, maybe you could do something with filestore? I assume
you version-control your site, so you could use filestore to extract the
date of the last patch modifying each particular file and store that as a
variable and then transclude it.
Another method might be editor-based. It would be maddeningly tedious to
update afield yourself but it is possible to script an editor to
https://www.gnu.org/software/emacs/manual/html_node/emacs/Time-Stamps.html#Time-Stamps
The default format there might not be YAML compatible but you can probably
come up with one which is.
--
gwern
https://www.gwern.net
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...