Documentation ¶
Index ¶
- func ApplyMacros(content string, macros *Macros) string
- func OutputFilename(path string) string
- func ParseDate(datestring string, location *time.Location) (time.Time, error)
- func PrettyDate(datetime time.Time) string
- func PublishDate(datetime time.Time) string
- func RelativePath(base, path string) (string, error)
- func RenderArchives(context *SiteContext) error
- func RenderBlogIndex(context *SiteContext) error
- func RenderContent(page Page, macros *Macros) ([]byte, error)
- func RenderFeed(context *SiteContext) error
- func RenderPage(page Page, templates *Templates, macros *Macros) error
- func RenderTree(context *SiteContext, clean bool) (bool, error)
- func UpdatePageMacros(page Page, macros *Macros)
- type ByUnix
- type Config
- type Macros
- type Page
- type SiteContext
- type Templates
- func (templates *Templates) HasTemplate(key string) bool
- func (templates *Templates) Load(filename string) error
- func (templates *Templates) Render(key string, macros *Macros) []byte
- func (templates *Templates) RenderFooter(key string, macros *Macros) []byte
- func (templates *Templates) RenderHeader(key string, macros *Macros) []byte
- Bugs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyMacros ¶
ApplyMacros applies the passed macros to the passed string.
func OutputFilename ¶
OutputFilename returns the filename with `.html` instead of `.text`.
func PrettyDate ¶
PrettyDate returns a nicely rendered timestamp for this page, based on its date.
func PublishDate ¶
PublishDate returns a RSS friendly timestamp.
func RelativePath ¶
RelativePath updates the internal path, and removes the actual filesystem portion. For instance, if the path is `/srv/sites/teaincodeout` this function would be passed `/srv/sites/teaincodeout` so that `/srv/sites/teaincodeout/blog/index.text` has a path of `blog`.
func RenderArchives ¶
func RenderArchives(context *SiteContext) error
RenderArchives renders the Blog Archives page, which is found at `blogpath/archives.html`. This renders a page with a reverse chronological listing of blog posts, under the month that they were released.
func RenderBlogIndex ¶
func RenderBlogIndex(context *SiteContext) error
RenderBlogIndex renders the Blog Index page, which is found at `blogpath/index.html`. This renders a page with up to the user configured blog limit post content inline, with a link to the archives page.
func RenderContent ¶
RenderContent renders a Page's content with the passed macros to HTML.
func RenderFeed ¶
func RenderFeed(context *SiteContext) error
RenderFeed renders the RSS Feed, which is found at `blogpath/rss.xml`. This performs a very similar operation to RenderBlogIndex, however there is no limit and the data is wrapped in XML templates, not HTML.
func RenderPage ¶
RenderPage renders the passed page, with the passed templates and the passed Macros. This renders the page to the filesystem and closes it.
func RenderTree ¶
func RenderTree(context *SiteContext, clean bool) (bool, error)
RenderTree renders all active HTML data in the site tree. If clean is set to true, re-renders all content, not just content that has changed.
func UpdatePageMacros ¶
UpdatePageMacros updates the macros array to include some macros specific to the passed Page.
Types ¶
type Config ¶
type Config struct { Macros map[string]string `json:"macros"` // A map of key-value pairs representing macros. BlogLimit int `json:"blog_limit"` // The number of blog posts to list on the Index page. BlogPath string `json:"blog_path"` // The directory that the blog posts are located under. Location string `json:"location"` // The timezone that dates will be processed under. }
Config is a type that matches what the user can modify directly. For instance, the macros, the number of blog posts to show in a listing, and the directory that the blog posts exist in.
type Macros ¶
type Macros struct {
// contains filtered or unexported fields
}
Macros are a simple, key-value pair used to do simple string replacements. The contents of the macro key are replaced with the macro value.
Macro keys always show in templates and pages as beginning with a `$` character.
BUG(caj): Unexpected behaviour may occur when two Macros have similar starting values. For example: $PAGE and $PAGEPATH.
func NewMacros ¶
NewMacros creates a new Macros list, starting with a capacity passed by the developer.
type Page ¶
type Page struct { Title string `json:"title"` // This Page's title. Template string `json:"template"` // The template to use when rendering the page. Date time.Time `json:"date"` // The date line for page page. Path string // The path to the directory that the page will be saved in. // contains filtered or unexported fields }
Page represents the pre-rendered pages in the system. These are files whose filenames end in `.text`, which contain metadata, followed by a Markdown body.
A Page can be rendered to HTML by calling `RenderPage()` and passing the page in question.
An example page would be:
Title: Page Title Date: 2017-03-25 22:01 Template: post --- # Header Page content follows.
This page would be rendered to an HTML page with the title "Page Title", with the date based on the Date field, using the template "post".
func NewPage ¶
NewPage creates a new page with the passed path. The path should end in `.text` if you would like the page to be picked up by the auto-renderer.
func PostListing ¶
PostListing returns a reverse-chronologically ordered listing of blog pages, based off of the passed path.
func SiteListing ¶
SiteListing creates a listing of all pages in the system, regardless of if they're blog posts or not.
func (*Page) HasChanged ¶
HasChanged returns true if the original Page is newer than the rendered version
type SiteContext ¶
type SiteContext struct { Location *time.Location // The timezone to treat all parsed time in. Config *Config // The options for this site. Templates *Templates // The templates store to use when rendering this site. // contains filtered or unexported fields }
SiteContext contains the information relating to this site/blog. The loaded templates and configuration is tracked in this structure.
func NewContext ¶
func NewContext(path, templatePath, configPath string) (*SiteContext, error)
NewContext creates a new SiteContext and loads the appropriate data from the filesystem.
func (*SiteContext) LoadConfig ¶
func (context *SiteContext) LoadConfig() error
LoadConfig loads a configuration file and returns a Config struct containing both macros and site configuration.
func (*SiteContext) LoadTemplates ¶
func (context *SiteContext) LoadTemplates() error
LoadTemplates reloads the templates from the passed templates directory.
func (*SiteContext) Macros ¶
func (context *SiteContext) Macros() *Macros
Macros returns the macros defined in the user configuration.
func (*SiteContext) Path ¶
func (context *SiteContext) Path() string
Path returns the absolute site root.
type Templates ¶
type Templates struct {
// contains filtered or unexported fields
}
Templates is a struct which contains all of the templates found in the templates directory.
Rather than doing filesystem lookups, the Templates stores all of the possible templates accessible by the system, and those templates can be queried at any point.
Templates has a few functions for rendering, which are used to render Pages into their final, HTML version.
func LoadTemplates ¶
LoadTemplates loads all of the templates in the template directory specified in the path parameter.
func NewTemplates ¶
NewTemplates creates a new Templates list, initialized with a certain capacity.
func (*Templates) HasTemplate ¶
HasTemplate verifies if a template exists
func (*Templates) RenderFooter ¶
RenderFooter renders the footer version of the template referenced by key, and falls back to the default "footer.html" template, if needed.
Notes ¶
Bugs ¶
Unexpected behaviour may occur when two Macros have similar starting values. For example: $PAGE and $PAGEPATH.