Front matter from Netlify CMS [solved]

Hi

Repo is here https://github.com/mshiner/bkvelo - I have Front matter defined as follows in my archetype for a Ride

+++
title = “{{ replace .Name “-” " " | title }}”
date = {{ .Date }}
draft = false
categories = “Group Ride”
rideDate = {{ .Date }}
expiryDate = {{ .Date }}
startFrom = “Brent Knoll Village Hall”
duration = “4h”
+++

I added Netlify CMS - here is the section from the CMS config.yml

collections:

  • name: “rides” # Used in routes, e.g., /admin/collections/blog
    label: “Rides” # Used in the UI
    label_singular: “Ride” # Used in the UI, ie: “New Ride”
    description: >
    Rides - share what you are doing.
    folder: “content/rides” # The path to the folder where the documents are stored
    create: true # Allow users to create new documents in this collection
    slug: “{{slug}}” # Filename template, e.g., YYYY-MM-DD-title.md
    fields: # The fields for each document, usually in front matter
    • {label: “Title”, name: “title”, widget: “string”}
    • {label: “Creation Date”, name: “date”, widget: “datetime”}
    • {label: “Draft”, name: “draft”, widget: “boolean”, default: false}
    • {label: “Categories”, name: “categories”, widget: “select”, options: [“Audax”, “Casuual/Family Ride”, “Cyclocross”, “Fixed”, “Group Ride”, “Sportive”]}
    • {label: “Ride Date”, name: “rideDate”, widget: “datetime”}
    • {label: “Expires”, name: “expiryDate”, widget: “datetime”}
    • {label: “Start From”, name: “startFrom”, widget: “string”}
    • {label: “Duration”, name: “duration”, widget: “string”}
    • {label: “Body”, name: “body”, widget: “markdown”}

When I save a ride through CMS Netlify saves the front matter as YAML like so…


title: Test Ride day 1
date: ‘2018-03-18T15:13:28+00:00’
draft: false
categories: Group Ride
rideDate: ‘2018-03-21T15:00:28+00:00’
expiryDate: ‘2018-03-31T00:00:00+01:00’
startFrom: Oudenaarde Belgium
duration: 2 Hours

Testing out the bikes before the 3 days of cobbles.

Consequently my build fails with errors because the dates are strings and I do some .Unix stuff to determine if a ride is in the future.

Any ideas how I can correct for this?

Thanks M

Have you taken a look at time in the docs? I believe it does what you’re looking for in the first example :slight_smile:

Hi cmal

Thanks for that - trouble is if I create my content locally as well as in the cms then the format of the dates will be different from content from the CMS - I don’t understand why Netlify saves what is a timestamp as a string.

Regs
M

Chaps

If anyone trips over this - had to just do a convert of the timestamp using the time function as cmal indicated. Cheers mate!

Regs M

1 Like