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

Time stamping entries #9

Closed
mmistakes opened this Issue Aug 10, 2016 · 8 comments

Comments

Projects
None yet
2 participants
@mmistakes

mmistakes commented Aug 10, 2016

Is there a preferred way to capture the datetime of an entry? Noticed there's a {@timestamp} placeholder in the documentation but couldn't figure out how to use that for capturing comment data.

I'm looking to get .yml datafiles something like this to iterate on and spit out in my Jekyll layouts:

name: Your Name
date: 2015-06-26T04:39:00-04:00   #comment timestamp
email:   #MD5 hash
url:
message: "Your message."

Thanks!

@eduardoboucas

This comment has been minimized.

Owner

eduardoboucas commented Aug 10, 2016

The {@timestamp} placeholder can only be used to specify the filename and the path of the data file. At the moment, there is no way to inject a timestamp into the actual entry (which is what you're after, right?).

If so, it's definitely something I can implement. How do you envision this working from a user perspective? As in, how would you tell Staticman that it needs to inject the current date in a field called date? And things like the format to use, etc.

Any thoughts will be appreciated. :)

@mmistakes

This comment has been minimized.

mmistakes commented Aug 10, 2016

Yes, injecting a timestamp of some sort into each entry is what I'm after. If that can happen at the time of it's creation that would be great.

As a workaround I was trying to find a way to assign a date to a hidden field

<input type="hidden" name="field[date]" value="{{ site.time }}">

But obviously that went nowhere as I couldn't really find a way to grab the current time dynamically. site.time is only as good as your last deployment...

So if there was a way to trigger Staticman to include a timestamp or date value in the datafile at creation that would be beneficial.

Noticed in your personal site repo that you were capturing the date in your comment datafiles. That's what led me down this road. That and comment's typically include that sort of metadata.

@eduardoboucas

This comment has been minimized.

Owner

eduardoboucas commented Aug 10, 2016

Ah, you're right! That was being used in the previous iteration of Staticman and hasn't been implemented in the rebuilt app.

I'll add this tomorrow. Thanks.

@eduardoboucas

This comment has been minimized.

Owner

eduardoboucas commented Aug 11, 2016

I've added support for this using the concept of generated fields. At the moment, the only type of generated field is date, but we could introduce other dynamic fields in the future (like geolocation, language, etc.)

I need to add this to the docs, but in the meantime here's an example of how you can use it to add a date field with a timestamp to your posts:

  generatedFields:
    date:
      type: date
      options:
        format: timestamp

The current formats accepted are timestamp, for a numeric Unix timestamp, or iso8601 (the default) for a ISO-8601 date string.

Let me know of any issues.

@mmistakes

This comment has been minimized.

mmistakes commented Aug 11, 2016

This is fantastic. Seems to be working well for iso8601.

One thing I noticed... and I don't know if this is an issue or not.

Using format: iso8601 generates something like date: '2016-08-11T12:27:02.882Z' which when filtered through Liquid {{ date | date_to_xmlschema }} outputs as 2016-08-11T13:27:02+01:00 as expected.

But if switched to format: timestamp it looks like the year is completely wrong when filtered.

date: 1470919084344 filtered with {{ date | date_to_xmlschema }} outputs as 48581-07-27T11:32:24+01:00

Any ideas there? I was able to filtered other Unix timestamps OK with date_to_xmlschema, so not sure what the deal is.

Example: date: 1431361080 filters to 2015-05-11T17:18:00+01:00.

@eduardoboucas

This comment has been minimized.

Owner

eduardoboucas commented Aug 11, 2016

That's because timestamp is returning the Unix timestamp in milliseconds. I've added a timestamp-seconds which returns seconds. Give that one a try.

I wonder if I should make seconds the default and create a timestamp-milliseconds.

@mmistakes

This comment has been minimized.

mmistakes commented Aug 11, 2016

Tested timestamp-seconds and that works. I don't use Unix timestamps enough to have a preference either way. The fact that the format can be set to either works for me.

Maybe lean on the side of defaulting to seconds since that's how some of the Jekyll/Liquid filters are looking for it. Not sure what other static-site gens prefer.

@eduardoboucas

This comment has been minimized.

Owner

eduardoboucas commented Aug 30, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment