modulepackage
0.0.0-20210301115436-8a0b0a782d0a
Repository: https://github.com/gernest/front.git
Documentation: pkg.go.dev
# README
front


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 theJSONHandler
for how to implement one. - Support YAML frontmatter
- Support JSON frontmatter.
Installation
go get github.com/gernest/front
How to use
package main
import (
"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 file for the full license text.
# Functions
JSONHandler implements HandlerFunc interface.
NewMatter creates a new Matter instance.
YAMLHandler decodes ymal string into a go map[string]interface{}.
# Variables
ErrIsEmpty is an error indicating no front matter was found.
ErrUnknownDelim is returned when the delimiters are not known by theFrontMatter implementation.
# Type aliases
No description provided by the author