cobalt.rs
cobalt.rs copied to clipboard
Automatic date (published) and modified date (updated)
Maintainer's notes
- [x] Date from filename
- [x] Update dates on
cobalt publish
- [ ] Inferring modified time from git
I know this is possible and I'm trying to see where it could fit in. But is this something that would even be wanted as a feature? Adding a custom tag as described in liquid rust for these things I think would be awesome.
I'm going to try implementing this on my own but wanted an idea of if this is planned anyway or explicitly not wanted.
Thanks!
Hi,
I would really like such a feature. I would guess two possible source to get the date off:
- Directory name YYYYMMDD
- Multiple Directories YYYY/MM/DD
see my posts_in_subfolders test:
https://github.com/cobalt-org/cobalt.rs/tree/master/tests/fixtures/posts_in_subfolder/posts
Maybe getting it from a filename like YYYYMMDD post.md would be a third possible solution.
Greetings
Uwe
Thanks, I'll try to get a dirty implementation of this this weekend. There's filetime that would allow us to get it from the file properties in a cross platform way. Problem with that is passing a bunch of file data around instead of just reading the contents.
For Jekyll compatibility, we'd want to support YYYY-MM-DD-name.extension
More specifically, their filename regexes are
DATELESS_FILENAME_MATCHER = %r!^(?:.+/)*(.*)(\.[^.]+)$!
DATE_FILENAME_MATCHER = %r!^(?:.+/)*(\d{4}-\d{2}-\d{2})-(.*)(\.[^.]+)$!
Would something like filetime work? I didn't think git preserved mtime so it'd work on your local machine but if you rely on something like travis to generate your site, then the dates will all be off.
I didn't know that regarding git. However, at least having automatic creation time with filetime would be cool. Plus, Creation time is already one of the properties so it would be easier to add anyway.
I've not seen any pages confirming, but I doubt git also preserves ctime and atime as well.
To be more automatic than extracting from the file name, I think you'll need to dig into the git history with all that entails (gracefully handling non-git code with some config flags to control behavior at minimum; SCM abstraction ideally).
True. Starting a git log
with args and then parsing that per file could be good. Or maybe just don't support travis builds ;)
Is there a reason we couldn't use std::fs::Metadata
here? It makes sense to me to use Metadata::created()
where possible, and emit a build error if we can't determine the created date from the filesystem AND the user doesn't have a value defined in the page/post.
created
is relative to the machine.
On the other hand, we could look in git for more information. The question is how we should interpret it.
published
- first commit?
- first commit marked "is draft = false"
- latest commit?
modified
- latest commit
#324 adds inferring the date
from the file name (not directories).
Hugo has an optionally-enabled feature for exposing git information. One aspect of it is it sets a modification time on a file based on the last commit to the file
See https://gohugo.io/variables/git/#lastmod
Also, #325 added a cobalt publish <filename>
which will remove the draft flag (not move the file atm) and set the date
to now.