Documentation
¶
Index ¶
- Variables
- type Config
- type OfflineRenderer
- type OnlineRenderer
- type Page
- type RenderContext
- type Renderer
- type Set
- type Site
- func (s *Site) AddPage(p *Page)
- func (s *Site) AddTemplate(key string, byts []byte) error
- func (s *Site) PageByPath(path string) (*Page, error)
- func (s *Site) PageBySlug(slug string) (*Page, error)
- func (s *Site) Pages() []*Page
- func (s *Site) RemovePageByPath(path string) *Page
- func (s *Site) Tag(tag string) ([]*Page, error)
- func (s *Site) Tags() []string
- func (s *Site) Template(key string) (*template.Template, error)
- func (s *Site) Type(typ string) ([]*Page, error)
Constants ¶
This section is empty.
Variables ¶
var ( // Rendering errors ErrTemplateNotFound = errors.New("template not found") ErrSlugNotFound = errors.New("slug not found") ErrPathNotFound = errors.New("path not found") ErrTagNotFound = errors.New("tag not found") ErrTypeNotFound = errors.New("type not found") // Page validation/parsing errors. ErrMissingSlug = errors.New("invalid slug") ErrMissingType = errors.New("invalid type") ErrMissingPath = errors.New("missing path") ErrMissingTitle = errors.New("missing title") ErrMissingFrontmatter = errors.New("missing frontmatter") // Frontmatter delimiter FrontmatterDelimiter = []byte("---") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { InputDir string OutputDir string UseLocalRootUrl bool // if true, use http://localhost:8080 as the root url QuiescentSecs int // period to wait before re-rendering pages on a template change }
Config for sites.
type OfflineRenderer ¶
type OfflineRenderer struct {
Config Config
}
Render a site in one-shot mode.
func (*OfflineRenderer) Render ¶
func (r *OfflineRenderer) Render() error
Renders the site and returns any error generated during rendering. Renders in one-shot and returns when rendering is complete.
type OnlineRenderer ¶
type OnlineRenderer struct { Config Config // contains filtered or unexported fields }
Renders a site in online mode. Watches the input directory for changes and renders them as files are changed. When a template changes, all pages are re-rendered currently. Re-rendering after a template change waits for a quiescence period to allow time for intital rendering of the site.
TODO: only re-render when a page is affected by the template change.
func (*OnlineRenderer) Render ¶
func (r *OnlineRenderer) Render() (err error)
Start rendering. Watches the filesystem for any updates and renders updates as they arrive. Does not return unless rendering failed to start.
type Page ¶
type Page struct { // Required fields. FilePath string // filename relative to the input directory UrlPath string // url relative to the site root Slug string `yaml:"slug"` Title string `yaml:"title"` Type string `yaml:"type"` IsRaw bool OrderHint int // Fields for markdown pages. Draft bool `yaml:"draft"` Date time.Time `yaml:"date"` Tags []string `yaml:"tags"` Ordering string `yaml:"ordering"` // contains filtered or unexported fields }
A Page.
func (*Page) Content ¶
Return the content of the page, converted to HTML. Reads page from filesystem.
func (*Page) RawContent ¶
Get the raw content from the file. Reads the file each call.
type RenderContext ¶
Context within which a page is rendered and defines top-level functions that can be called from the template.
func (RenderContext) PageReference ¶
func (ctx RenderContext) PageReference(slug string) (*Page, error)
Get a page, given a slug.
func (RenderContext) RenderPage ¶
func (ctx RenderContext) RenderPage(p *Page) ([]byte, error)
type Set ¶
type Set[T comparable] struct { sync.RWMutex // contains filtered or unexported fields }
Simple set implementation.
func NewSet ¶
func NewSet[T comparable]() *Set[T]
type Site ¶
type Site struct { sync.Mutex Title string `yaml:"title"` RootUrl string `yaml:"root_url"` // contains filtered or unexported fields }
A Site.
func (*Site) AddTemplate ¶
Add a template keyed by the given string.
func (*Site) PageByPath ¶
Lookup page by input path.
func (*Site) PageBySlug ¶
Lookup page by slug.
func (*Site) RemovePageByPath ¶
Remove the page with the given path and return the removed page. If page does not exist, returns nil.