cobalt.rs icon indicating copy to clipboard operation
cobalt.rs copied to clipboard

Automatic date (published) and modified date (updated)

Open krruzic opened this issue 7 years ago • 12 comments

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!

krruzic avatar Mar 02 '17 06:03 krruzic

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

uwearzt avatar Mar 02 '17 14:03 uwearzt

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.

krruzic avatar Mar 02 '17 20:03 krruzic

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})-(.*)(\.[^.]+)$!

epage avatar Mar 09 '17 03:03 epage

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.

epage avatar Mar 09 '17 03:03 epage

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.

krruzic avatar Mar 09 '17 03:03 krruzic

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).

epage avatar Mar 09 '17 04:03 epage

True. Starting a git log with args and then parsing that per file could be good. Or maybe just don't support travis builds ;)

krruzic avatar Mar 09 '17 04:03 krruzic

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.

sudoforge avatar Apr 12 '17 18:04 sudoforge

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

epage avatar Oct 31 '17 03:10 epage

#324 adds inferring the date from the file name (not directories).

epage avatar Nov 09 '17 04:11 epage

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

epage avatar Nov 09 '17 04:11 epage

Also, #325 added a cobalt publish <filename> which will remove the draft flag (not move the file atm) and set the date to now.

epage avatar Nov 09 '17 04:11 epage