front

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2020 License: Zlib, MIT Imports: 2 Imported by: 0

Documentation

Overview

Package front provides YAML frontmatter unmarshalling.

Example
package main

import (
	"fmt"
	"log"

	"christine.website/cmd/site/internal/front"
)

var markdown = []byte(`---
title: Ferrets
authors:
  - Tobi
  - Loki
  - Jane
---
Some content here, so
interesting, you just
want to keep reading.`)

type article struct {
	Title   string
	Authors []string
}

func main() {
	var a article

	content, err := front.Unmarshal(markdown, &a)
	if err != nil {
		log.Fatalf("error unmarshalling: %s", err)
	}

	fmt.Printf("%#v\n", a)
	fmt.Printf("%s\n", string(content))
}
Output:

front_test.article{Title:"Ferrets", Authors:[]string{"Tobi", "Loki", "Jane"}}

Some content here, so
interesting, you just
want to keep reading.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(b []byte, v interface{}) (content []byte, err error)

Unmarshal parses YAML frontmatter and returns the content. When no frontmatter delimiters are present the original content is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL