https://github.com/gernest/front
extracts frontmatter from text files with ease with golang.
https://github.com/gernest/front
extracts-frontmatter frontmatter golang
Last synced: 6 months ago
JSON representation
extracts frontmatter from text files with ease with golang.
- Host: GitHub
- URL: https://github.com/gernest/front
- Owner: gernest
- License: mit
- Created: 2015-08-11T22:38:35.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-03-01T11:54:36.000Z (about 4 years ago)
- Last Synced: 2024-06-18T15:18:59.670Z (10 months ago)
- Topics: extracts-frontmatter, frontmatter, golang
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 55
- Watchers: 4
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# front [](https://travis-ci.org/gernest/front) [](https://godoc.org/github.com/gernest/front)[](https://coveralls.io/github/gernest/front?branch=master)
extracts frontmatter from text files with ease.
## Features
* Custom delimiters. You are free to register any delimiter of your choice. Provided its a three character string. e.g `+++`, `$$$`, `---`, `%%%`
* Custom Handlers. Anything that implements `HandlerFunc` can be used to decode the values from the frontmatter text, you can see the `JSONHandler` for how to implement one.
* Support YAML frontmatter
* Support JSON frontmatter.## Installation
go get github.com/gernest/front
## How to use
```go
package mainimport (
"fmt"
"strings""github.com/gernest/front"
)var txt = `+++
{
"title":"front"
}
+++# Body
Over my dead body
`func main() {
m := front.NewMatter()
m.Handle("+++", front.JSONHandler)
f, body, err := m.Parse(strings.NewReader(txt))
if err != nil {
panic(err)
}fmt.Printf("The front matter is:\n%#v\n", f)
fmt.Printf("The body is:\n%q\n", body)
}
```Please see the tests formore details
## Licence
This project is under the MIT Licence. See the [LICENCE](LICENCE) file for the full license text.