Skip to content
Separates a files front matter from its content
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
spec
src
.gitignore
.travis.yml
LICENSE
README.md
makefile
shard.yml

README.md

front_matter.cr

Docs GitHub release Build Status

Separates a files front matter from its content. Unlike Jekyll and others this implementation is format agnostic.

Front Matter?

Front matter is metadata you can add to a document. The data is located between a pair of --- lines at the start of a document. With this parser the format can be any format you would like.

---
The front matter
---

The content

A more practical and complicated example using YAML front matter with Liquid to generate some HTMLc ould look like below.

---
layout: post
title: Blogging Like a Hacker
---

<h1>{{ title }}</h1>
<p>This is the content.</p>

One of the most common, but not the only, uses for front matter is to use this with Liquid (crystal implementation), or a similar templating language.

Installation

Add this to your application's shard.yml:

dependencies:
  front_matter:
    github: chris-huxtable/front_matter.cr

Usage

require "front_matter"

To process a file:

FrontMatter.open("/path/to/file") { |front_matter, content_io|

	# Do something with the front matter and content.
	# Parse the front matter as YAML, JSON or something else?

}

Alternatively you can parse an IO so long as it supports the #.seek method

File.open(filename, "r") { |fd|
	FrontMatter.parse(fd) { |front_matter, content_io|

		# Do something with the front matter and content.
		# Parse the front matter as YAML, JSON or something else?

	}
}

Contributing

  1. Fork it ( https://github.com/chris-huxtable/front_matter.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

You can’t perform that action at this time.