models

package
v2.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2018 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobCSS template.CSS

GlobCSS is a byte slice containing the style CSS of the renderer

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.

RSS is the main RSS feed

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)

SplitFile splits the yaml part of a file from the actual markdown content

func UpdateRSSFeed

func UpdateRSSFeed()

UpdateRSSFeed will update the items in the RSS feed to reflect the changes

Types

type Author

type Author struct {
	Name    string `yaml:"name"`
	Twitter string `yaml:"twitter"`
	Site    string `yaml:"site"`
	Github  string `yaml:"github"`
	Avatar  string `yaml:"avatar"`
}

Author represents the author of a single article

func GetGlobalAuthor

func GetGlobalAuthor() *Author

GetGlobalAuthor retrieves the author configured in the configuration file Returns a nil pointer if nothing is defined

func (Author) IsEmpty

func (a Author) IsEmpty() bool

IsEmpty checks if all the fields of an Author are blank

type Gitalk

type Gitalk struct {
	Enabled      bool     `yaml:"enabled"`
	ClientID     string   `yaml:"client_id"`
	ClientSecret string   `yaml:"client_secret"`
	Repo         string   `yaml:"repo"`
	Owner        string   `yaml:"owner"`
	Admin        []string `yaml:"admin"`
}

Gitalk is a struct holding all the information necessary to make gitalk work

func GetGitalk

func GetGitalk() *Gitalk

GetGitalk returns a gitalk struct

type MetaData

type MetaData struct {
	Title       string   `yaml:"title"` // Mandatory
	Description string   `yaml:"description"`
	Banner      string   `yaml:"banner"`
	Author      *Author  `yaml:"author,omitempty"`
	Slug        string   `yaml:"slug"`
	Tags        []string `yaml:"tags"`
	Date        string   `yaml:"date"` // Mandatory
	Draft       bool     `yaml:"draft"`
}

MetaData is a struct that helps the unmarshalling of the yaml header in markdown files.

func (*MetaData) GenerateSlug

func (m *MetaData) GenerateSlug() string

GenerateSlug will generate a slug if necessary, based on the title of the article. Otherwise it will return the slug set in the metadata

func (*MetaData) Validate

func (m *MetaData) Validate() error

Validate validates that the metada is valid

type Page

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

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) GetShare

func (p Page) GetShare() *url.URL

GetShare returns an URL for the Twitter share button

func (Page) GetURL

func (p Page) GetURL() *url.URL

GetURL returns the URL of the page

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

type PageSlice

type PageSlice []*Page

PageSlice is a slice of pointer to pages

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.

func (PageSlice) Len

func (p PageSlice) Len() int

Len is part of sort.Interface.

func (PageSlice) Less

func (p PageSlice) Less(i, j int) bool

Less is part of sort.Interface. We use count as the value to sort by

func (PageSlice) Swap

func (p PageSlice) Swap(i, j int)

Swap is part of sort.Interface.

Jump to

Keyboard shortcuts

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