Netlify-cms: Automatic lastEdited / lastPublished field population

Created on 2 Dec 2020  路  2Comments  路  Source: netlify/netlify-cms

Is your feature request related to a problem? Please describe.

I'm building a sitemap generator for a site, and understand that including the publish date for articles can help with SEO on more recent posts. Currently it looks like this would have to be entered manually for each post.

Describe the solution you'd like

I'm wondering if it's possible to expose a config option or a widget that would automatically add the date to a post, and keep it updated on every publish.

Describe alternatives you've considered

Additional context

feature

Most helpful comment

Hi, @neefrehman! I am new to Netlify CMS, but It looks like a valid case for registering-to-cms-events. Not tested it, but something like

CMS.registerEventListener({
  name: 'preSave'
  handler: ({ entry }) => {
    return entry.get('data').set('lastEdited', new Date().toISOString())
  },
});

should do the trick. We also should set a 'lastEdited' as hidden field, I think.

All 2 comments

Hi, @neefrehman! I am new to Netlify CMS, but It looks like a valid case for registering-to-cms-events. Not tested it, but something like

CMS.registerEventListener({
  name: 'preSave'
  handler: ({ entry }) => {
    return entry.get('data').set('lastEdited', new Date().toISOString())
  },
});

should do the trick. We also should set a 'lastEdited' as hidden field, I think.

@TimPchelintsev thanks! this is exactly the kind of solution I was looking for!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marcojakob picture marcojakob  路  3Comments

Narno picture Narno  路  3Comments

chriskirknielsen picture chriskirknielsen  路  3Comments

TomPichaud picture TomPichaud  路  3Comments

bkroggel picture bkroggel  路  3Comments