models

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2016 License: MIT Imports: 13 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MPages map[string]*Page

MPages is the map containing all the articles. The key is the slug of the article for low complexity access when querying a slug.

View Source
var SPages pageSlice

SPages is a sorted slice of pages. Sorted by date, it is used to render all the pages on the index page.

Functions

func ParseDir

func ParseDir(dir string) error

ParseDir cycles through a directory and parses each file one by one.

func SplitFile

func SplitFile(fn string) ([]byte, []byte, error)

Types

type Page

type Page struct {
	Raw         string
	Markdown    template.HTML
	Title       string
	Description string
	Author      string
	Date        time.Time
	DateFmt     string
	Tags        []string
	File        string
	Slug        string
}

Page is the main struct. It contains everything needed to render the article.

func NewPageFromFile

func NewPageFromFile(fn string) (*Page, error)

NewPageFromFile parses a file, inserts it in the map and slice, and returns a *Page instance

func (*Page) Insert

func (p *Page) Insert(batch bool) error

Insert will try to insert the file in the MPages map and SPages slice. It will also validates that no pages have the same slug, and sort the SPages slice in case it's not a batch insertion. (A batch insertion means after all the inserts, SPages will be sorted manually)

func (*Page) ParseFile

func (p *Page) ParseFile(fn string) error

ParseFile parses a whole file and fills the Page struct.

func (*Page) ParseMarkdown

func (p *Page) ParseMarkdown(b []byte)

ParseMarkdown will simply parse the markdown b and put it inside the Page structure.

func (*Page) ParseMetadata

func (p *Page) ParseMetadata(h []byte) error

ParseMetadata parses the metadata on top of the markdown files. It will also raise errors when mandatory fields aren't present, or some slugs are duplicates.

func (*Page) Pop

func (p *Page) Pop()

Pop removes a Page (in case the file is deleted for example)

func (*Page) UpdateFromFile

func (p *Page) UpdateFromFile(fn string) error

UpdateFromFile parses the file once more

Jump to

Keyboard shortcuts

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