gostatic

package
v0.0.0-...-c6b3ac7 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: ISC Imports: 23 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.27"

Current gostatic version

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 = `` /* 399-byte string literal not displayed */
View Source
var ExampleFeed = `` /* 1196-byte string literal not displayed */
View Source
var ExampleIndex = `` /* 196-byte string literal not displayed */
View Source
var ExampleMakefile = `
GS ?= gostatic

compile:
	$(GS) config

w:
	$(GS) -w config
`
View Source
var ExamplePost = `` /* 129-byte string literal not displayed */
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,
	"replacere":      ReplaceRe,
	"split":          Split,
	"contains":       Contains,
	"starts":         Starts,
	"ends":           Ends,
	"matches":        Matches,
	"refind":         ReFind,
	"markdown":       Markdown,
	"exec":           Exec,
	"exectext":       ExecText,
	"excerpt":        Excerpt,
	"even":           Even,
	"odd":            Odd,
	"count":          Count,
	"reading_time":   ReadingTime,
	"some":           Some,
	"dir":            Dir,
	"base":           Base,
}

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 Base

func Base(value string) string

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 Count

func Count(text string) int

func Cut

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

func Dir

func Dir(value string) string

func Ends

func Ends(needle, value string) bool

Ends returns true if `value' ends with `needle'.

func Even

func Even(value int) bool

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 Exec

func Exec(cmd string, arg ...string) (string, error)

Exec runs a `cmd` with all supplied arguments

func ExecText

func ExecText(cmd string, arg ...string) (string, error)

ExecText runs a `cmd` with all supplied arguments with stdin bound to last argument

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 Matches

func Matches(pattern, value string) (bool, error)

Matches returns tre if regexp `pattern` matches string `value'.

func NonEmptySplit

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

func Odd

func Odd(value int) bool

func ReFind

func ReFind(pattern, value string) (string, error)

func ReadingTime

func ReadingTime(text string) int

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 ReplaceRe

func ReplaceRe(pattern, repl, value string) (string, error)

func SliceStringIndexOf

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

func Some

func Some(strs ...interface{}) string

func Split

func Split(sep, value string) []string

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

func Starts

func Starts(needle, value string) bool

Starts returns true if `value' starts with `needle'.

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 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 (*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) Has

func (page *Page) Has(field, value string) bool

func (*Page) Is

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

func (*Page) Name

func (page *Page) Name() string

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.

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)

SetWasRead is 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 ParseYamlHeader

func ParseYamlHeader(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 NewPages

func NewPages(site *Site, path string) PageSlice

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() *PageSlice

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

func (pages PageSlice) Where(field, value string) *PageSlice

func (PageSlice) WhereNot

func (pages PageSlice) WhereNot(field, value string) *PageSlice

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

func (rules RuleMap) MatchedRules(path string) (string, []*Rule)

type Site

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

	ForceRefresh bool

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

func NewSite

func NewSite(configPath string, procs ProcessorMap) *Site

make new instance of Site

func (*Site) AddPages

func (site *Site) AddPages(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) Reconfig

func (site *Site) Reconfig()

read site config, templates and find all eligible pages

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