Creating object from a text

Lori 2 Lori * rocks


Today I've discovered an amazing package Yaml Front Matter, which can be used to manage different data in text.

I use this npm package to parse yaml at the front of a file. It places the parsed content plus the rest of the file's content into an object.

As I write, this post looks like this (I write in markdown- it's great but this package can be used on other file formats as well):

title : Creating object from a text
date : 2015-08-29
Today I've discovered amazing package - [Yaml Front Matter]

Thanks to this package it is easy to create an object for the later use:

  title: 'Creating object from a text',
  date: '2015-08-29',
  __content: 'Today I've discovered amazing package - [Yaml Front Matter]

It is also extremely easy to insert more details to the document:

contact: {
  email: '',
  address: 'some location'
pets: [
match: /pattern/gim,
run: [Function],

How is it used on this page exactly? As you can see below, I use "title", "date" and "__content" to create my posts with a little help of coffeescript.

@article class: 'content', =>
  @h1 post.title
  if then @h6 =>
    date = moment
    @span 'Published: '
    @time datetime: date.format(), date.calendar null,
      sameDay: '[Today]',
      nextDay: '[Tomorrow]',
      nextWeek: 'dddd',
      lastDay: '[Yesterday]',
      lastWeek: '[Last] dddd'
      sameElse : "MMMM Do YYYY"

  markdown post.__content

I hope you liked this post and you'll try make a use of front matter in some of your projects.

Ps. I manage date using moment and I write about it on the post Replace absolute date with relative one.