content

package
v0.0.0-...-142b142 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PostsFolder is the default folder for blog posts.
	PostsFolder = "posts"
	// PagesFolder is the default folder for blog pages.
	PagesFolder = "pages"
	// FileDateFormat is the date format required in a post's header.
	FileDateFormat = "2006-Jan-02"
)
View Source
const (
	TemplateFolder = "templates"
	DisplayFolder  = "displays"
	IncludeFolder  = "includes"
)

TemplatesFolder is the default folder for templates.

Variables

This section is empty.

Functions

func Render

func Render(e Entry) string

Render generates HTML from an entries markdown content.

Types

type BaseContext

type BaseContext struct {
	BlogTitle    string
	BlogSubtitle string
	BlogAuthor   string
	BlogYear     string
	BlogEmail    string
	BlogURL      string
	BlogNav      []NavItemContext
}

BaseContext stores basic context information like title, author etc.

type ByAge

type ByAge []Post

ByAge implements a interface to sort a slice of posts by publishing date.

func (ByAge) Len

func (b ByAge) Len() int

func (ByAge) Less

func (b ByAge) Less(i, j int) bool

func (ByAge) Swap

func (b ByAge) Swap(i, j int)

type Entry

type Entry interface {
	GetContent() string
	GetURL() string
	GetTitle() string
}

Entry has content and be located by an URL.

type ErrorContext

type ErrorContext struct {
	BaseContext
	Message string
}

ErrorContext stores error information.

type Index

type Index struct {
	// Posts stores all blog posts.
	Posts []Post

	// Pages stores all blog pages.
	Pages []Page

	// PostBySlug matches each slug to its post.
	PostBySlug map[string]*Post

	// PageBySlug matches each slug to its page.
	PageBySlug map[string]*Page

	Resolver URLResolver
}

func NewIndex

func NewIndex(cfg *config.Config, resolver URLResolver) (*Index, error)

func (*Index) AddPage

func (c *Index) AddPage(data *ParseData) error

AddPage creates a new page from the parsed data.

func (*Index) AddPost

func (c *Index) AddPost(data *ParseData) error

AddPost creates a new post from the parsed data.

func (*Index) LatestPosts

func (c *Index) LatestPosts(count int) []Post

LatestPosts returns a slice of the latest blog posts.

type IndexContext

type IndexContext struct {
	BaseContext
	LatestPosts []Post
}

IndexContext stores a list of the latest posts.

type NavItemContext struct {
	Title string
	URL   string
}

NavItemContext stores the information of a navigation item.

type NavigationLink struct {
	Title string
	URL   string
}
func (n *NavigationLink) GetContent() string
func (n *NavigationLink) GetTitle() string
func (n *NavigationLink) GetURL() string

type Page

type Page struct {
	Title    string
	Slug     string
	Content  string
	Resolver URLResolver
}

Page stores a title, a page slug and the body content.

func (*Page) GetContent

func (p *Page) GetContent() string

GetContent returns the content body of the page.

func (*Page) GetTitle

func (p *Page) GetTitle() string

GetTitle returns the title of the page.

func (*Page) GetURL

func (p *Page) GetURL() string

GetURL generates a URL from the page route url and the page slug.

type PageContext

type PageContext struct {
	BaseContext
	PageTitle   string
	PageContent template.HTML
	PageURL     string
}

PageContext stores additional information for pages.

type ParseData

type ParseData struct {
	Title       string `yaml:"title"`
	Subtitle    string `yaml:"subtitle"`
	PublishDate string `yaml:"date"`
	Slug        string `yaml:"slug"`
	// contains filtered or unexported fields
}

ParseData stores the parsed data of a file.

func (*ParseData) Content

func (p *ParseData) Content() string

Content returns the parsed content.

func (*ParseData) SetContent

func (p *ParseData) SetContent(c string)

SetContent sets the parsed content.

type Post

type Post struct {
	Title       string
	Subtitle    string
	PublishDate time.Time
	Slug        string
	Content     string
	Resolver    URLResolver
}

Post stores a title, a page slug and the body content.

func (*Post) Age

func (p *Post) Age() int64

Age returns the age of the post in seconds.

func (*Post) GetContent

func (p *Post) GetContent() string

GetContent returns the content body of the post.

func (*Post) GetTitle

func (p *Post) GetTitle() string

GetTitle returns the title of the post.

func (*Post) GetURL

func (p *Post) GetURL() string

GetURL generates a URL from the post route url and the post slug.

type PostContext

type PostContext struct {
	BaseContext
	PostTitle    string
	PostSubtitle string
	PostDate     string
	PostContent  template.HTML
	PostURL      string
}

PostContext stores additional information for posts.

type Templater

type Templater struct {
	Config *config.Config
	// contains filtered or unexported fields
}

func NewTemplater

func NewTemplater(cfg *config.Config, index *Index) (*Templater, error)

NewTemplater loads the templates from the blog folder.

func (*Templater) AddNavItem

func (t *Templater) AddNavItem(e Entry)

AddNavItem adds a item to the navigation.

func (*Templater) ClearCache

func (t *Templater) ClearCache()

ClearCache clears the context cache.

func (*Templater) ClearNav

func (t *Templater) ClearNav()

func (*Templater) NewBaseContext

func (t *Templater) NewBaseContext() *BaseContext

NewBaseContext either creates a new BaseContext from the global blog configuration or returns the cached version.

func (*Templater) NewErrorContext

func (t *Templater) NewErrorContext(err error) *ErrorContext

NewErrorContext creates a new error context.

func (*Templater) NewIndexContext

func (t *Templater) NewIndexContext() *IndexContext

NewIndexContext either creates a new index context or returns the cached version.

func (*Templater) NewPageContext

func (t *Templater) NewPageContext(slug string) (*PageContext, error)

NewPageContext either creates a new page context or returns the cached version.

func (*Templater) NewPostContext

func (t *Templater) NewPostContext(slug string) (*PostContext, error)

NewPostContext either creates a new post context or returns the cached version.

func (*Templater) RenderPage

func (t *Templater) RenderPage(w io.Writer, name string, context interface{}) error

RenderPage renders a page or throws an error if the template is missing.

type URLResolver

type URLResolver interface {
	Page(string) string
	Post(string) string
}

Jump to

Keyboard shortcuts

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