Gatsby: Add publishedAt to Contentful nodes

Created on 5 Oct 2017  路  14Comments  路  Source: gatsbyjs/gatsby

@Khaledgarbaya re: https://stackoverflow.com/questions/46561916/how-to-retrieve-published-post-date-from-query-in-gatsby-with-contentful

Should we just add the publishedAt and updatedAt fields? Seems like an oversight on my part that they weren't added originally.

Most helpful comment

@Khaledgarbaya,
There may be a misunderstanding here. It looks like #2398 does not add the publishedAt field. Instead, it adds the createdAt and updatedAt fields.

Looks like publishedAt is only returned with the Content Management API, and not with the Content Delivery API.

All 14 comments

Hey @KyleAMathews, yeah sure I can do that.

Please do! I'm setting up a blog with Contentful, and this is pretty essential data.

馃憤 Would really appreciate this!

Yay! This would be really helpful. :+1:

This was added in https://github.com/gatsbyjs/gatsby/pull/2398 but forgot to close the issue, sorry.

@Khaledgarbaya,
There may be a misunderstanding here. It looks like #2398 does not add the publishedAt field. Instead, it adds the createdAt and updatedAt fields.

Looks like publishedAt is only returned with the Content Management API, and not with the Content Delivery API.

Yes @Khaledgarbaya , publishedAt is not returned.

What @bradgarropy said

Looks like publishedAt is only returned with the Content Management API, and not with the Content Delivery API.

in delivery API the equivalent of publishedAt is updatedAt

What @bradgarropy said

Looks like publishedAt is only returned with the Content Management API, and not with the Content Delivery API.

in delivery API the equivalent of publishedAt is updatedAt

@Khaledgarbaya, the problem comes when I have a draft in contentful, I am not able to know it in gatbsy since I receive both createdAt and updatedAt in published and drafts elements.

Is there any way to know if an element is in published or draft? I just want to show and generate pages of published elements

In addition, the elements in draft don't have all the required fields completed and a double-check in gatbsy would be required.

Is there any way to know if an element is in published or draft? I just want to show and generate pages of published elements

The source plugin is using the delivery API so you will only get the published entries.

Can you explain more you use case because maybe I misunderstood something

The source plugin is using the delivery API so you will only get the published entries.

Can you explain more you use case because maybe I misunderstood something

Sure!

That's a good solution, but it doesn't seem to work in my case.

1) I create a new entry in contenful, which is saved as "DRAFT".
2) I direct gatbsy develop and receive all the entries (published and draft).
3) My application breaks because it is prepared only for published entries, not for incomplete drafts.

"gatsby-source-contentful": "^2.0.5",
"contentful-import": "^7.4.1",
"gatsby": "^2.0.29",

Hi @Khaledgarbaya , any potencial solution?

What are the uses cases of the Preview API?

Hey @jorgemarrero,

Unfortunately, the only solution for this is to use a Date field in your content model to act as the publisher at and you can change it however you want.

I have a related issue. If you update an old blog post e.g. because there is a typo and you want to correct it, it suddenly becomes the newest blog post with updatedAt. Whereas with createdAt it takes the day it was originally created as a draft. It would therefore be really helpful if the "firstPublishedAt" field would be available.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

3CordGuy picture 3CordGuy  路  3Comments

rossPatton picture rossPatton  路  3Comments

KyleAMathews picture KyleAMathews  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

magicly picture magicly  路  3Comments