core

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const AssetDir = "public"
View Source
const ContentDir = "content"
View Source
const TargetDir = "output"
View Source
const TemplateDir = "templates"

Variables

View Source
var MarkupExtensions = []string{"md", "mkd"}
View Source
var MetadataExtensions = []string{"yaml", "yml"}
View Source
var TemplateExtensions = []string{"mustache", "mu", "stache"}

Functions

func BasenameWithoutExtension

func BasenameWithoutExtension(path string) string

func CopyFile

func CopyFile(src, dst string) error

func DirExists

func DirExists(path string) bool

func FindDirsWithFiles

func FindDirsWithFiles(dir string, extensions ...string) ([]string, error)

func FindFiles

func FindFiles(dir string) ([]string, error)

FindFiles returns a slice containing the absolute path of _all_ regular files below the given directory.

func FirstFileWithExtension added in v1.3.0

func FirstFileWithExtension(dir string, basename string, extensions ...string) string

func PageListValues

func PageListValues(pages []*Page, ctx *Page) []map[string]interface{}

func PageValues

func PageValues(p *Page, ctx *Page) map[string]interface{}

func ProcessMetadata

func ProcessMetadata(file string) (map[string]interface{}, error)

func TagList added in v1.3.0

func TagList(page *Page) []map[string]interface{}

func TagSlug added in v1.3.0

func TagSlug(name string) string

Types

type Checkpoint

type Checkpoint struct {
	// contains filtered or unexported fields
}

Checkpoint is a full listing of all files and their respective modification timestamps of a specific directory.

func (*Checkpoint) Equals

func (c *Checkpoint) Equals(o *Checkpoint) bool

Equals compares this checkpoint to another one. If an empty Checkpoint to compare with is given, or both structures do not share the exact same files, or any of the files has a different modification timestamp, they will not be regarded as “equal.”

type Page

type Page struct {
	// available directly after construction.
	Slug     string
	Name     string
	DiskPath string
	Tacker   *Tacker
	Floating bool
	Date     time.Time

	// first available after call to Init()
	Parent        *Page
	SiblingsAndMe []*Page
	Children      []*Page
	Posts         []*Page
	Assets        map[string]struct{}
	Variables     map[string]interface{}
	Template      string
	// contains filtered or unexported fields
}

Page is the main structure holding page content. Some of the fields are only available after the page has been initialized using Init().

func NewPage

func NewPage(tacker *Tacker, realPath string) *Page

NewPage creates a new page structure for the specified Tacker based on the given path of the page's directory. No file i/o will take place here just yet.

func (*Page) Ancestors

func (p *Page) Ancestors() []*Page

Ancestors returns a slice of all of this page's ancestors, starting with the immediate parent page and ending with the root page. The Page must be Init()ed prior to calling this.

func (*Page) Generate

func (p *Page) Generate() error

Generate renders the current page given all the content and metadata read from disk and the configured template. If not done already, calling this function will initialize the page using Init().

func (*Page) Init

func (p *Page) Init() error

Init initializes the page content, by reading the content and metadata from the disk, resolving the used template and creating the necessary structures to reference other pages from this one.

func (p *Page) Permalink() string

Permalink return an absolute path to the current page based on its and it's ancestor pages' slugs. The Page must be Init()ed prior to calling this.

func (*Page) Post added in v1.3.0

func (p *Page) Post() bool

Post returns `true` if the current page has a post date defined as part of the content directory name.

func (*Page) Root added in v1.1.0

func (p *Page) Root() bool

Root determines if the current page is the root page of the website being tacked. The root page might be stored in the top-level content directory or a directory with the slug "index" just below the top level.

func (*Page) Siblings

func (p *Page) Siblings() []*Page

Siblings returns a slice of all sibling pages of the current one. The Page must be Init()ed prior to calling this.

func (*Page) TargetDir

func (p *Page) TargetDir() []string

TargetDir returns the (absolute) path to the directory which will contain this page's HTML and further assets. The Page must be Init()ed prior to calling this.

type Tacker

type Tacker struct {
	BaseDir     string
	Metadata    map[string]interface{}
	Pages       []*Page
	Navigation  []*Page
	Posts       []*Page
	Tags        map[string][]*Page
	TagNames    map[string]map[string]int
	TagIndex    *Page
	Logger      *log.Logger
	DebugLogger *log.Logger
	Strict      bool
}

Tacker is the main configuration structure of tack. A Tacker is used by the command-line interface, or programmatically when tacking a website from within third-party code.

func NewTacker

func NewTacker(dir string) (*Tacker, error)

NewTacker creates a new tack configuration structure based on the files found in the directory provided.

func (*Tacker) Checkpoint

func (t *Tacker) Checkpoint() (*Checkpoint, error)

Checkpoint stats all the files within the source directory and stores the names and modification timestamps so we're able to compare this list with a future checkpoint without the need to set up file watchers.

func (*Tacker) Debug added in v1.3.0

func (t *Tacker) Debug(format string, args ...interface{})

func (*Tacker) FindTemplate

func (t *Tacker) FindTemplate(name string) (*Template, error)

func (*Tacker) HasChanges

func (t *Tacker) HasChanges(prev *Checkpoint) (bool, *Checkpoint, error)

HasChanges will create a fresh Checkpoint for the current Tacker and compare it to the previous one. The functions returns if there are changes between the checkpoints (or none was provided in the first) place, as well the new Checkpoint, and any error which might have occurred while creating it.

func (*Tacker) Log

func (t *Tacker) Log(format string, args ...interface{})

func (*Tacker) Reload

func (t *Tacker) Reload() error

Reload re-reads all site content and re-builds the page structure.

func (*Tacker) Tack

func (t *Tacker) Tack() error

Tack is the main “tacking” functionality: All pages are rendered into the output directory by filling the respective templates with the page content.

func (*Tacker) Tag added in v1.3.0

func (t *Tacker) Tag(name string) Tag

type Tag added in v1.3.0

type Tag struct {
	Name      string
	Slug      string
	Count     int
	Permalink string
}

type Template

type Template struct {
	*mustache.Template
}

func (*Template) Render

func (t *Template) Render(page *Page, w io.Writer) error

Jump to

Keyboard shortcuts

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