Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic date (published) and modified date (updated) #197

Open
2 of 3 tasks
krruzic opened this issue Mar 2, 2017 · 12 comments
Open
2 of 3 tasks

Automatic date (published) and modified date (updated) #197

krruzic opened this issue Mar 2, 2017 · 12 comments
Labels
enhancement Improve the expected

Comments

@krruzic
Copy link

krruzic commented Mar 2, 2017

Maintainer's notes

  • Date from filename
  • 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!

@uwearzt
Copy link
Contributor

uwearzt commented Mar 2, 2017

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

@krruzic
Copy link
Author

krruzic commented Mar 2, 2017

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.

@epage
Copy link
Member

epage commented Mar 9, 2017

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
Copy link
Member

epage commented Mar 9, 2017

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.

@krruzic
Copy link
Author

krruzic commented Mar 9, 2017

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.

@epage
Copy link
Member

epage commented Mar 9, 2017

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

@krruzic
Copy link
Author

krruzic commented Mar 9, 2017

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

@epage epage self-assigned this Mar 31, 2017
@sudoforge
Copy link

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.

@epage
Copy link
Member

epage commented Oct 31, 2017

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 added a commit to epage/cobalt.rs that referenced this issue Nov 5, 2017
This is inspired by cobalt-org#197 and Jekyll.

Jekyll gets the filename from a file.  The main difference between
Jekyll and this change is that we aren't supporting 2-digit years.

In cobalt-org#197, the idea was brought up of extracting the date from the
directory structure.  I like this approach.  I could imagine having at
least year directories (don't blog enough to make day directories worth
while).  The challenge comes in how to detect this.
@epage epage removed their assignment Nov 9, 2017
@epage
Copy link
Member

epage commented Nov 9, 2017

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

@epage
Copy link
Member

epage commented Nov 9, 2017

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
Copy link
Member

epage commented Nov 9, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve the expected
Projects
None yet
Development

No branches or pull requests

4 participants