Custom date field in sortable_fields?


I have successfully implemented Netlify CMS on my website and so far it’s working perfectly. However, I have a question regarding sortable_fields. Is it possible to use a custom date field in this parameter?

I’m setting dates in my frontmatter like this:

title: "String"
date: 2018-01-18
description: "String"

And this is my config:

  name: git-gateway
  repo: <username>/<repo>
publish_mode: editorial_workflow
media_folder: 'static/images/'
public_folder: 'images/'
site_url: <url>
display_url: <url>
  - name: 'blog'
    create: true
    label: 'Blog'
    label_singular: 'Post'
    folder: 'content/blog'
    path: '{{slug}}/index'
    media_folder: 'assets/'
    preview_path: '{{dirname}}'
      preview: true
    sortable_fields: ['title', '']
      - { label: 'Title', name: 'title', widget: 'string' }
      - { label: 'Date', name: 'date', widget: 'datetime' }
      - { label: 'Description', name: 'description', widget: 'string' }
      - { label: 'Body', name: 'body', widget: 'markdown' }

The date seems to work fine to sort in an asending order (older posts at top), however I’m not able to sort the posts in an descending order (newer posts at top). Is it something that I’m doing wrong or if it’s not supposed to work at all?

Not sure if it’s relevant, but I’m using Hugo.

Hi @hrishikesh and sorry for being late to reply.

When specifying sortable_fields you don’t need to prefix the fields with fields. so:

sortable_fields: ['title', 'date']

should work.

Also, please note the following issue about sorting dates that were saved using a custom format.

Ahh, as I suspected. The problem is because of non ISO date. Well, since I currently have only 7 posts, it’s possible to change the dates in my case and it’s good to see the issue is being worked on.

Thanks a lot!