site

package
v0.0.0-...-44e12ef Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: BSD-2-Clause Imports: 31 Imported by: 0

Documentation

Overview

Package site implements everything related to building a site.

Index

Constants

View Source
const (
	ConfigFileName = "site.yml"
	AssetsFileName = "assets.yml"
	CSPFileName    = "csp.yml"

	AssetsDirName   = "assets" // just a convention, currently used for watching only
	IncludesDirName = "includes"
	LayoutsDirName  = "layouts"
	PagesDirName    = "pages"
	PostsDirName    = "posts"
	DraftsDirName   = "drafts"
	OutDirName      = "out"

	DefaultPermalink = "blog/:year/:month/:day/:name/"

	DefaultPostLayout     = "post"
	DefaultPageLayout     = "default"
	DefaultTagIndexLayout = "tag"
)

Variables

View Source
var (
	HTMLExtensions     = []string{".html", ".htm"}
	MarkdownExtensions = []string{".markdown", ".md"}
	PostExtensions     = []string{".html", ".htm", ".markdown", ".md"}
)
View Source
var NotPageError = errors.New("not a page or post")

Functions

func EnableCache

func EnableCache(value bool)

func IsNotPage

func IsNotPage(err error) bool

Types

type Config

type Config struct {
	// Loadable from YAML.
	Name       string                     `yaml:"name"`
	Author     string                     `yaml:"author"`
	Permalink  string                     `yaml:"permalink"`
	URL        string                     `yaml:"url"`
	Static     *StaticConfig              `yaml:"static"`
	Filters    map[string]interface{}     `yaml:"filters"`
	Properties map[string]interface{}     `yaml:"properties"`
	Search     *SearchConfig              `yaml:"search"`
	Markup     *markup.Options            `yaml:"markup"`
	Compress   *filewriter.CompressConfig `yaml:"compress"`
	TagIndex   *TagIndexConfig            `yaml:"tagindex"`
	Sitemap    string                     `yaml:"sitemap"`

	// Generated.
	Date    time.Time
	Posts   Posts            `yaml:"-"`
	Tags    map[string]Posts `yaml:"-"`
	TagList []string         `yaml:"-"`
}

func (Config) PostsByTag

func (c Config) PostsByTag(tag string) Posts

func (Config) TagURL

func (c Config) TagURL(tag string) (string, error)

type Page

type Page struct {
	ShortContent string // content before <!--more-->, or empty if none
	Basedir      string
	Filename     string
	// contains filtered or unexported fields
}

func LoadPage

func LoadPage(basedir, filename string) (p *Page, err error)

func (*Page) Content

func (p *Page) Content() string

func (*Page) FileInfo

func (p *Page) FileInfo() os.FileInfo

func (*Page) InSitemap

func (p *Page) InSitemap() bool

func (*Page) Meta

func (p *Page) Meta() map[string]interface{}

func (*Page) SitemapEntry

func (p *Page) SitemapEntry() sitemap.Entry

func (*Page) URL

func (p *Page) URL() string

type Post

type Post struct {
	Page
	Tags []string
	Date time.Time
}

func LoadPost

func LoadPost(basedir, filename, outNameTemplate string) (p *Post, err error)

type Posts

type Posts []*Post

func (Posts) ByYear

func (pp Posts) ByYear() []postsByYear

func (Posts) From

func (pp Posts) From(n int) Posts

func (Posts) Len

func (pp Posts) Len() int

func (Posts) Less

func (pp Posts) Less(i, j int) bool

func (Posts) Limit

func (pp Posts) Limit(n int) Posts

func (Posts) Sort

func (pp Posts) Sort()

func (Posts) Swap

func (pp Posts) Swap(i, j int)

type SearchConfig

type SearchConfig struct {
	Index   string   `yaml:"index"`
	Exclude []string `yaml:"exclude"`
}

type Site

type Site struct {
	BaseDir     string
	Config      *Config
	Assets      *assets.Collection
	Layouts     *layouts.Collection
	PageFilters *filters.Collection
	CSP         csp.Directives
	Includes    map[string]string
	// contains filtered or unexported fields
}

func Open

func Open(dir string) (s *Site, err error)

func (*Site) Build

func (s *Site) Build() (err error)

func (*Site) Clean

func (s *Site) Clean() error

func (*Site) CopyFile

func (s *Site) CopyFile(filename string) error

func (*Site) LayoutData

func (s *Site) LayoutData() interface{}

func (*Site) LayoutFuncs

func (s *Site) LayoutFuncs() layouts.FuncMap

func (*Site) LoadAssets

func (s *Site) LoadAssets() error

func (*Site) LoadCSP

func (s *Site) LoadCSP() error

func (*Site) LoadConfig

func (s *Site) LoadConfig() error

func (*Site) LoadIncludes

func (s *Site) LoadIncludes() (err error)

func (*Site) LoadLayoutFuncs

func (s *Site) LoadLayoutFuncs() error

func (*Site) LoadLayouts

func (s *Site) LoadLayouts() (err error)

func (*Site) LoadPageFilters

func (s *Site) LoadPageFilters() error

func (*Site) LoadPosts

func (s *Site) LoadPosts() (err error)

func (*Site) MakePost

func (s *Site) MakePost(title string, tags string, link string) (string, error)

MakePost creates a new post file with the given title. It returns the filename of the created file.

func (*Site) ProcessAssets

func (s *Site) ProcessAssets() error

func (*Site) RenderAssets

func (s *Site) RenderAssets() error

func (*Site) RenderPage

func (s *Site) RenderPage(pagesDir, relname string) error

func (*Site) RenderPages

func (s *Site) RenderPages() error

func (*Site) RenderPost

func (s *Site) RenderPost(p *Post) error

func (*Site) RenderPosts

func (s *Site) RenderPosts() error

func (*Site) RenderSitemap

func (s *Site) RenderSitemap() error

func (*Site) RenderTag

func (s *Site) RenderTag(tag string) error

func (*Site) RenderTagsIndex

func (s *Site) RenderTagsIndex() error

func (*Site) Serve

func (s *Site) Serve(addr string) error

func (*Site) SetCleanBeforeBuilding

func (s *Site) SetCleanBeforeBuilding(clean bool)

func (*Site) SetDevMode

func (s *Site) SetDevMode(dev bool)

func (*Site) StartWatching

func (s *Site) StartWatching() (err error)

func (*Site) StopWatching

func (s *Site) StopWatching()

type StaticConfig

type StaticConfig struct {
	Path   string `yaml:"path"`
	URL    string `yaml:"url"`
	DevURL string `yaml:"dev_url"`
	Assets bool   `yaml:"assets"`
}

type TagIndex

type TagIndex struct {
	Page
	Tag      string
	Filename string
	TagPosts Posts
}

func NewTagIndex

func NewTagIndex(tag, permalink string) *TagIndex

func (*TagIndex) Content

func (p *TagIndex) Content() string

func (*TagIndex) FileInfo

func (p *TagIndex) FileInfo() os.FileInfo

func (*TagIndex) Meta

func (p *TagIndex) Meta() map[string]interface{}

func (*TagIndex) URL

func (p *TagIndex) URL() string

type TagIndexConfig

type TagIndexConfig struct {
	Permalink string `yaml:"permalink"`
	Layout    string `yaml:"layout"`
}

Jump to

Keyboard shortcuts

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