gostatic

package
v0.0.0-...-0e89488 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2015 License: ISC Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateUnknown = iota
	StateChanged
	StateUnchanged
	StateIgnored
)
View Source
const (
	// Preprocessor is a processor which will be executed during initialization
	// stage
	Pre = 1 << iota
	Hidden
	Post
)
View Source
const (
	VERSION = "2.4"
)

Variables

View Source
var DATEFORMATS = []string{
	time.RFC3339,
	time.RFC3339Nano,
	"2006-01-02T15:04:05Z-07:00",
	"2006-01-02T15:04:05Z",
	"2006-01-02 15:04:05 -0700",
	"2006-01-02 15:04:05 -07",
	"2006-01-02 15:04:05",
	"2006-01-02 15:04",
	"2006-01-02 15",
	"2006-01-02",
	"06-01-02",
}
View Source
var (
	DEBUG bool = false
)
View Source
var ExampleConfig = `` /* 398-byte string literal not displayed */
View Source
var ExampleFeed = `` /* 1187-byte string literal not displayed */
View Source
var ExampleIndex = `` /* 183-byte string literal not displayed */
View Source
var ExampleMakefile = `
GS ?= gostatic

compile:
	$(GS) config

w:
	$(GS) -w config
`
View Source
var ExamplePost = `
title: First Post
date: 2012-12-12
tags: blog
----
My first post with [gostatic](http://github.com/piranha/gostatic/).
`
View Source
var ExampleStyle = `
/* put your style rules here */
`
View Source
var ExampleTemplate = `` /* 1291-byte string literal not displayed */
View Source
var FalsyValues = map[string]bool{
	"false": true,
	"False": true,
	"FALSE": true,
	"f":     true,
}
View Source
var TemplateFuncMap = template.FuncMap{
	"changed":        HasChanged,
	"cut":            Cut,
	"hash":           Hash,
	"version":        Versionize,
	"truncate":       Truncate,
	"strip_html":     StripHTML,
	"strip_newlines": StripNewlines,
	"replace":        Replace,
	"replacen":       ReplaceN,
	"split":          Split,
	"contains":       Contains,
	"markdown":       Markdown,
	"excerpt":        Excerpt,
}

TemplateFuncMap contains the mapping of function names and their corresponding Go functions, to be used within templates.

View Source
var VarRe = regexp.MustCompile(`\$\(([^\)]+)\)`)

Functions

func Capitalize

func Capitalize(s string) string

func Contains

func Contains(needle, value string) bool

Contains returns true if `needle' is contained within `value'.

func CopyFile

func CopyFile(srcPath, dstPath string) (n int64, err error)

func Cut

func Cut(begin, end, value string) (string, error)

func Excerpt

func Excerpt(text string, maxWords int) string

Excerpt takes an input string (for example, text from a blog post), and truncates it to the amount of words given in maxWords. For instance, given the text:

"The quick brown fox jumps, over the lazy dog."

and the given maxWords of 0, 1, 3, 4, and 6, 999, it will return in order:

"" // an empty string
"The [...]"
"The quick brown [...]"
"The quick brown fox [...]"
"The quick brown fox jumps, over the lazy dog."

func HasChanged

func HasChanged(name string, value interface{}) bool

func Hash

func Hash(value string) string

func IsDir

func IsDir(path string) (bool, error)

func Markdown

func Markdown(source string) string

func NonEmptySplit

func NonEmptySplit(s string, sep string) []string

func Replace

func Replace(old, new, value string) string

Replace replaces `old' with `new' in the given value string and returns it. There is no limit on the amount of replacements.

func ReplaceN

func ReplaceN(old, new string, n int, value string) string

ReplaceN replaces the `old' string with the `new' string in the given value, n times. If n < 0, there is no limit on the number of replacements.

func SliceStringIndexOf

func SliceStringIndexOf(haystack []string, needle string) int

func Split

func Split(sep, value string) []string

Split splits the value using the separator sep, and returns it as a string slice.

func StripHTML

func StripHTML(value string) string

StripHTML removes HTML tags from the value string and returns it.

func StripNewlines

func StripNewlines(value string) string

StripNewlines removes all \r and \n characters from the value string, and returns it as such.

func TrimSplitN

func TrimSplitN(s string, sep string, n int) []string

func Truncate

func Truncate(length int, value string) string

Truncate truncates the value string to maximum of the given length, and returns it.

func Versionize

func Versionize(current *Page, value string) (string, error)

func Watch

func Watch(s *Site)

todo make this function to method of Site

func Watcher

func Watcher(config *SiteConfig) (chan string, error)

func WriteExample

func WriteExample(dir string) error

func WriteFile

func WriteFile(dir string, fn string, content string) error

Types

type Command

type Command string

Command is a command belonging to a Rule. For example, `markdown', `directorify'.

func (Command) Matches

func (cmd Command) Matches(prefix Command) bool

type CommandList

type CommandList []Command

CommandList is a slice of Commands.

type Page

type Page struct {
	PageHeader

	Site    *Site `json:"-"`
	Rule    *Rule
	Pattern string
	Deps    PageSlice `json:"-"`

	Source  string
	Path    string
	ModTime time.Time
	// contains filtered or unexported fields
}

func NewPage

func NewPage(site *Site, path string) *Page

func (*Page) Changed

func (page *Page) Changed() bool

func (*Page) Content

func (page *Page) Content() string

func (*Page) FullPath

func (page *Page) FullPath() string

func (*Page) Is

func (page *Page) Is(path string) bool

func (*Page) Next

func (page *Page) Next() *Page

func (*Page) OutputPath

func (page *Page) OutputPath() string

func (*Page) Peek

func (page *Page) Peek() error

Peek is used to run those processors which should be done before others can find out about us. Two actual examples include 'config' and 'rename' processors right now.

func (*Page) Prev

func (page *Page) Prev() *Page

func (*Page) Process

func (page *Page) Process() (*Page, error)

func (*Page) Raw

func (page *Page) Raw() string

func (*Page) Rel

func (page *Page) Rel(path string) string

func (*Page) Render

func (page *Page) Render() (n int64, err error)

func (*Page) SetContent

func (page *Page) SetContent(content string)

func (*Page) SetState

func (page *Page) SetState(state int)

func (*Page) SetWasRead

func (page *Page) SetWasRead(wasread bool)

will be used for dynamically created pages

func (*Page) Url

func (page *Page) Url() string

func (*Page) UrlMatches

func (page *Page) UrlMatches(regex string) bool

func (*Page) UrlTo

func (page *Page) UrlTo(other *Page) string

func (*Page) WasRead

func (page *Page) WasRead() bool

func (*Page) WriteTo

func (page *Page) WriteTo(writer io.Writer) (n int64, err error)
type PageHeader struct {
	Title string
	Tags  []string
	Date  time.Time
	Hide  bool
	Other map[string]string
}

func NewPageHeader

func NewPageHeader() *PageHeader

func ParseHeader

func ParseHeader(source string) *PageHeader

func (*PageHeader) ParseLine

func (cfg *PageHeader) ParseLine(line string, s *reflect.Value)

func (*PageHeader) SetValue

func (cfg *PageHeader) SetValue(key string, value string, s *reflect.Value)

type PageSlice

type PageSlice []*Page

func (PageSlice) ByPath

func (pages PageSlice) ByPath(s string) *Page

func (PageSlice) BySource

func (pages PageSlice) BySource(s string) *Page

func (PageSlice) Children

func (pages PageSlice) Children(root string) *PageSlice

func (PageSlice) First

func (pages PageSlice) First() *Page

func (PageSlice) Get

func (pages PageSlice) Get(i int) *Page

func (PageSlice) GlobSource

func (pages PageSlice) GlobSource(pattern string) *PageSlice

func (PageSlice) HasPage

func (pages PageSlice) HasPage(check func(page *Page) bool) bool

func (PageSlice) Last

func (pages PageSlice) Last() *Page

func (PageSlice) Len

func (pages PageSlice) Len() int

Sorting interface

func (PageSlice) Less

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

func (PageSlice) Next

func (pages PageSlice) Next(cur *Page) *Page

func (PageSlice) Prev

func (pages PageSlice) Prev(cur *Page) *Page

func (PageSlice) Reverse

func (pages PageSlice) Reverse()

func (PageSlice) Slice

func (pages PageSlice) Slice(from int, to int) PageSlice

func (PageSlice) Sort

func (pages PageSlice) Sort()

func (PageSlice) Swap

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

func (PageSlice) WithTag

func (pages PageSlice) WithTag(tag string) *PageSlice

type Processor

type Processor interface {
	Process(page *Page, args []string) error
	Description() string
	Mode() int
}

type ProcessorMap

type ProcessorMap map[string]Processor

func (ProcessorMap) ProcessorSummary

func (pm ProcessorMap) ProcessorSummary()

type Rule

type Rule struct {
	Deps     []string
	Commands CommandList
}

Rule is a collection of a slice of dependencies, with a slice of commands in the form of a CommandList.

func (*Rule) IsDep

func (rule *Rule) IsDep(page *Page) bool

func (*Rule) ParseCommand

func (rule *Rule) ParseCommand(cfg *SiteConfig, line string)

type RuleMap

type RuleMap map[string]*Rule

func (RuleMap) MatchedRule

func (rules RuleMap) MatchedRule(path string) (string, *Rule)

type Site

type Site struct {
	SiteConfig
	Template  *template.Template
	ChangedAt time.Time
	Pages     PageSlice

	ForceRefresh bool

	Processors map[string]Processor
	// contains filtered or unexported fields
}

func NewSite

func NewSite(config *SiteConfig, procs ProcessorMap) *Site

func (*Site) AddPage

func (site *Site) AddPage(path string)

func (*Site) Collect

func (site *Site) Collect()

func (*Site) FindDeps

func (site *Site) FindDeps()

func (*Site) Lookup

func (site *Site) Lookup(path string) *Page

func (*Site) PageBySomePath

func (site *Site) PageBySomePath(s string) *Page

func (*Site) Process

func (site *Site) Process() (int, error)

func (*Site) ProcessAll

func (site *Site) ProcessAll() error

func (*Site) ProcessCommand

func (s *Site) ProcessCommand(page *Page, cmd *Command, pre bool) error

func (*Site) Render

func (site *Site) Render()

func (*Site) Summary

func (site *Site) Summary()

type SiteConfig

type SiteConfig struct {
	Templates []string
	Base      string
	Source    string
	Output    string
	Rules     RuleMap
	Other     map[string]string
	// contains filtered or unexported fields
}

SiteConfig contains the data for a complete parsed site configuration file.

func NewSiteConfig

func NewSiteConfig(path string) (*SiteConfig, error)

NewSiteConfig parses the given `path' file to a *SiteConfig. Will return a nil pointer plus the non-nil error if the parsing has failed.

func (*SiteConfig) ParseRule

func (cfg *SiteConfig) ParseRule(line string) *Rule

func (*SiteConfig) ParseVariable

func (cfg *SiteConfig) ParseVariable(base string, line string)

func (*SiteConfig) SubVars

func (cfg *SiteConfig) SubVars(s string) string

Jump to

Keyboard shortcuts

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