blog

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2020 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package blog contains helpers for manipulating site and blog source files.

Index

Constants

View Source
const (
	HeaderTOML = "+++\n"
	HeaderYAML = "---\n"
)

The header of supported metadata types.

Variables

This section is empty.

Functions

func Slug

func Slug(filename string, meta Metadata) string

Slug attempts to guess the slug that the final page will have by checking if the metadata has a "slug" attribute and, if not, generating one from the filename (the full path should be passed so that trees such as "mypost/index.md" can be recognized as a post called 'mypost' and not 'index').

func WalkPages

func WalkPages(root string, walkFn filepath.WalkFunc) error

WalkPages walks the file tree rooted at root and calls walkFn for each page. It skips any files that do not end in the extension ".markdown" or ".md".

Types

type Metadata

type Metadata map[string]interface{}

Metadata contains parsed metadata including the type of the metadata in the file, and the offset of where the metadata ends.

func (Metadata) Decode

func (m Metadata) Decode(f io.Reader) (string, error)

Decode extracts metadata from the provided page. It assumes the first byte is the metadata header.

It supports decoding TOML wrapped in "+++\n" and YAML wrapped in "---\n" similar to Hugo or Jekyll and returns the header that it finds.

func (Metadata) GetBool

func (m Metadata) GetBool(key string) bool

GetBool parses the metadata value for key and returns it as a bool. If the underlying value is not a valid bool, an empty string is returned.

func (Metadata) GetString

func (m Metadata) GetString(key string) string

GetString parses the metadata value for key and returns it as a string. If the underlying value is not a valid string, an empty string is returned.

func (Metadata) GetTime

func (m Metadata) GetTime(key string) time.Time

GetTime parses the metadata value for key and returns it as a timestamp. If the underlying value is not already a time.Time, or a string that can be parsed into a valid time, a zero value will be returned.

Jump to

Keyboard shortcuts

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