wikifier

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: ISC Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PageOptExternalTypeQuiki is the external type for quiki sites.
	PageOptExternalTypeQuiki PageOptExternalType = "quiki"

	// PageOptExternalTypeMediaWiki is the external type for MediaWiki sites.
	PageOptExternalTypeMediaWiki = "mediawiki"

	// PageOptExternalTypeNone is an external type that can be used for websites that
	// perform no normalization of page targets beyond normal URI escaping.
	PageOptExternalTypeNone = "none"
)

Variables

This section is empty.

Functions

func CategoryName

func CategoryName(name string) string

CategoryName returns a clean category name.

func CategoryNameNE

func CategoryNameNE(name string) string

CategoryNameNE returns a clean category with No Extension.

func InjectPageOpt

func InjectPageOpt(page *Page, opt *PageOpt) error

InjectPageOpt extracts page options found in the specified page and injects them into the provided PageOpt pointer.

func MakeDir

func MakeDir(dir, name string)

MakeDir creates directories recursively.

func ModelName

func ModelName(name string) string

ModelName returns a clean model name.

func PageName

func PageName(name string) string

PageName returns a clean page name.

func PageNameExt

func PageNameExt(name, ext string) string

PageNameExt returns a clean page name with the provided extension.

func PageNameLink(name string) string

PageNameLink returns a clean page name without the extension.

func PageNameNE

func PageNameNE(name string) string

PageNameNE returns a clean page name with No Extension.

func ScaleString

func ScaleString(name string, retina []int) string

ScaleString returns a string of scaled image names for use in srcset.

func UniqueFilesInDir

func UniqueFilesInDir(dir string, extensions []string, thisDirOnly bool) ([]string, error)

UniqueFilesInDir recursively scans a directory for files matching the requested extensions, resolves symlinks, and returns a list of unique files. That is, if more than one link resolves to the same thing (as is the case for quiki page redirects), there is only one occurrence in the output.

Types

type AttributedObject

type AttributedObject interface {

	// getters
	Get(key string) (interface{}, error)
	GetBool(key string) (bool, error)
	GetStr(key string) (string, error)
	GetBlock(key string) (block, error)
	GetObj(key string) (AttributedObject, error)

	// setters
	Set(key string, value interface{}) error
	// contains filtered or unexported methods
}

An AttributedObject is any object on which you can set and retrieve attributes.

For example, a Page is an attributed object since it contains variables. Likewise, a Map is an attributed object because it has named properties.

type HTML

type HTML string

HTML encapsulates a string to indicate that it is preformatted HTML. It lets quiki's parsers know not to attempt to format it any further.

type List

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

List represents a list of items. It is a quiki data type as well as the base of many block types.

func NewList

func NewList(mb block) *List

NewList creates a new list, given the main block of the page it is to be associated with.

func (List) String

func (b List) String() string

type Map

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

Map represents a Key-value dictionary. It is a quiki data type as well as the base of many block types.

func NewMap

func NewMap(mb block) *Map

NewMap creates a new map, given the main block of the page it is to be associated with.

func (Map) Get

func (scope Map) Get(key string) (interface{}, error)

Get fetches a a value regardless of type.

The key may be segmented to indicate properties of each object (e.g. person.name).

If attempting to read a property of an object that does not support properties, such as a string, Get returns an error.

If the key is valid but nothing exists at it, Get returns (nil, nil).

func (Map) GetBlock

func (scope Map) GetBlock(key string) (block, error)

GetBlock is like Get except it always returns a block.

func (Map) GetBool

func (scope Map) GetBool(key string) (bool, error)

GetBool is like Get except it always returns a boolean.

func (Map) GetObj

func (scope Map) GetObj(key string) (AttributedObject, error)

GetObj is like Get except it always returns an AttributedObject.

func (Map) GetStr

func (scope Map) GetStr(key string) (string, error)

GetStr is like Get except it always returns a string.

If the value is HTML, it is converted to a string.

func (*Map) Keys

func (m *Map) Keys() []string

Keys returns a string of actual underlying map keys.

func (*Map) Map

func (m *Map) Map() map[string]interface{}

Map returns the actual underlying Go map.

func (*Map) OrderedKeys

func (m *Map) OrderedKeys() []string

OrderedKeys returns a string of map keys in the order provided in the source. Keys that were set internally (and not from quiki source code) are omitted.

func (Map) Set

func (scope Map) Set(key string, value interface{}) error

Set sets a value at the given key.

The key may be segmented to indicate properties of each object (e.g. person.name).

If attempting to write to a property of an object that does not support properties, such as a string, Set returns an error.

func (Map) String

func (b Map) String() string

type Page

type Page struct {
	Source   string   // source content
	FilePath string   // Path to the .page file
	VarsOnly bool     // True if Parse() should only extract variables
	Opt      *PageOpt // page options

	Images    map[string][][]int // references to images
	Models    map[string]bool    // references to models
	PageLinks map[string][]int   // references to other pages

	Wiki interface{} // only available during Parse() and HTML()
	// contains filtered or unexported fields
}

Page represents a single page or article, generally associated with a .page file. It provides the most basic public interface to parsing with the wikifier engine.

func NewPage

func NewPage(filePath string) *Page

NewPage creates a page given its filepath.

func NewPagePath

func NewPagePath(filePath, name string) *Page

NewPagePath creates a page given its filepath and relative name.

func NewPageSource

func NewPageSource(source string) *Page

NewPageSource creates a page given some source code.

func (*Page) Author

func (p *Page) Author() string

Author returns the page author's name, if any.

func (*Page) CSS

func (p *Page) CSS() string

CSS generates and returns the CSS code for the page's inline styles.

func (*Page) CacheExists

func (p *Page) CacheExists() bool

CacheExists is true if the page cache file exists.

func (*Page) CacheModified

func (p *Page) CacheModified() time.Time

CacheModified returns the page cache file time.

func (*Page) CachePath

func (p *Page) CachePath() string

CachePath returns the absolute path to the page cache file.

func (*Page) Categories

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

Categories returns a list of categories the page belongs to.

func (*Page) Created

func (p *Page) Created() time.Time

Created returns the page creation time.

func (*Page) Draft

func (p *Page) Draft() bool

Draft returns true if the page is marked as a draft.

func (*Page) Exists

func (p *Page) Exists() bool

Exists is true if the page exists.

func (*Page) FmtTitle

func (p *Page) FmtTitle() HTML

FmtTitle returns the page title, preserving any possible text formatting.

func (*Page) Generated

func (p *Page) Generated() bool

Generated returns true if the page was auto-generated from some other source content.

func (Page) Get

func (scope Page) Get(key string) (interface{}, error)

Get fetches a a value regardless of type.

The key may be segmented to indicate properties of each object (e.g. person.name).

If attempting to read a property of an object that does not support properties, such as a string, Get returns an error.

If the key is valid but nothing exists at it, Get returns (nil, nil).

func (Page) GetBlock

func (scope Page) GetBlock(key string) (block, error)

GetBlock is like Get except it always returns a block.

func (Page) GetBool

func (scope Page) GetBool(key string) (bool, error)

GetBool is like Get except it always returns a boolean.

func (Page) GetObj

func (scope Page) GetObj(key string) (AttributedObject, error)

GetObj is like Get except it always returns an AttributedObject.

func (Page) GetStr

func (scope Page) GetStr(key string) (string, error)

GetStr is like Get except it always returns a string.

If the value is HTML, it is converted to a string.

func (*Page) HTML

func (p *Page) HTML() HTML

HTML generates and returns the HTML code for the page. The page must be parsed with Parse before attempting this method.

func (*Page) Info

func (p *Page) Info() PageInfo

Info returns the PageInfo for the page.

func (p *Page) IsSymlink() bool

IsSymlink returns true if the page is a symbolic link to another file within the page directory. If it is symlinked to somewhere outside the page directory, it is treated as a normal page rather than a redirect.

func (*Page) Modified

func (p *Page) Modified() time.Time

Modified returns the page modification time.

func (*Page) Name

func (p *Page) Name() string

Name returns the resolved page name with extension.

This DOES take symbolic links into account. and DOES include the page prefix if applicable. Any prefix will have forward slashes regardless of OS.

func (*Page) NameNE

func (p *Page) NameNE() string

NameNE returns the resolved page name with No Extension.

func (*Page) OSName

func (p *Page) OSName() string

OSName is like Name, except it uses the native path separator. It should be used for file operations only.

func (*Page) OSNameNE

func (p *Page) OSNameNE() string

OSNameNE is like NameNE, except it uses the native path separator. It should be used for file operations only.

func (*Page) Parse

func (p *Page) Parse() error

Parse opens the page file and attempts to parse it, returning any errors encountered.

func (*Page) Path

func (p *Page) Path() string

Path returns the absolute path to the page as resolved. If the path does not resolve, returns an empty string.

func (*Page) Prefix

func (p *Page) Prefix() string

Prefix returns the page prefix.

For example, for a page named a/b.page, this is a. For a page named a.page, this is an empty string.

func (*Page) Redirect

func (p *Page) Redirect() string

Redirect returns the location to which the page redirects, if any. This may be a relative or absolute URL, suitable for use in a Location header.

func (*Page) RelName

func (p *Page) RelName() string

RelName returns the unresolved page filename, with or without extension. This does NOT take symbolic links into account. It is not guaranteed to exist.

func (*Page) RelNameNE

func (p *Page) RelNameNE() string

RelNameNE returns the unresolved page name with No Extension, relative to the page directory option. This does NOT take symbolic links into account. It is not guaranteed to exist.

func (*Page) RelPath

func (p *Page) RelPath() string

RelPath returns the unresolved file path to the page. It may be a relative or absolute path. It is not guaranteed to exist.

func (*Page) SearchPath

func (p *Page) SearchPath() string

SearchPath returns the absolute path to the page search text file.

func (Page) Set

func (scope Page) Set(key string, value interface{}) error

Set sets a value at the given key.

The key may be segmented to indicate properties of each object (e.g. person.name).

If attempting to write to a property of an object that does not support properties, such as a string, Set returns an error.

func (*Page) Title

func (p *Page) Title() string

Title returns the page title with HTML text formatting tags stripped.

func (*Page) TitleOrName

func (p *Page) TitleOrName() string

TitleOrName returns the result of Title if available, otherwise that of Name.

type PageInfo

type PageInfo struct {
	Path      string     `json:"omit"`                // absolute filepath
	File      string     `json:"file,omitempty"`      // name with extension, always with forward slashes
	Created   *time.Time `json:"created,omitempty"`   // creation time
	Modified  *time.Time `json:"modified,omitempty"`  // modify time
	Draft     bool       `json:"draft,omitempty"`     // true if page is marked as draft
	Generated bool       `json:"generated,omitempty"` // true if page was generated from another source
	Redirect  string     `json:"redirect,omitempty"`  // path page is to redirect to
	FmtTitle  HTML       `json:"fmt_title,omitempty"` // title with formatting tags
	Title     string     `json:"title,omitempty"`     // title without tags
	Author    string     `json:"author,omitempty"`    // author's name
}

PageInfo represents metadata associated with a page.

type PageOpt

type PageOpt struct {
	Name         string // wiki name
	MainPage     string // name of main page
	ErrorPage    string // name of error page
	Template     string // name of template
	MainRedirect bool   // redirect on main page rather than serve root
	Page         PageOptPage
	Host         PageOptHost
	Dir          PageOptDir
	Root         PageOptRoot
	Image        PageOptImage
	Category     PageOptCategory
	Search       PageOptSearch
	Link         PageOptLink
	External     map[string]PageOptExternal
	Navigation   []PageOptNavigation
}

PageOpt describes wiki/website options to a Page.

type PageOptCategory

type PageOptCategory struct {
	PerPage int
}

PageOptCategory describes wiki category options.

type PageOptDir

type PageOptDir struct {
	Wiki     string // path to wiki root directory
	Image    string // path to image directory
	Category string // path to category directory
	Page     string // path to page directory
	Model    string // path to model directory
	Markdown string // path to markdown directory
	Cache    string // path to cache directory
}

PageOptDir describes actual filepaths to wiki resources.

type PageOptExternal

type PageOptExternal struct {
	Name string              // long name (e.g. Wikipedia)
	Root string              // wiki page root (no trailing slash)
	Type PageOptExternalType // wiki type
}

PageOptExternal describes an external wiki that we can use for link targets.

type PageOptExternalType

type PageOptExternalType string

PageOptExternalType describes

type PageOptHost

type PageOptHost struct {
	Wiki string // HTTP host for the wiki
}

PageOptHost describes HTTP hosts for a wiki.

type PageOptImage

type PageOptImage struct {
	Retina     []int
	SizeMethod string
	Calc       func(file string, width, height int, page *Page) (w, h int)
	Sizer      func(file string, width, height int, page *Page) (path string)
}

PageOptImage describes wiki imaging options.

type PageOptLink struct {
	ParseInternal PageOptLinkFunction // internal page links
	ParseExternal PageOptLinkFunction // external wiki page links
	ParseCategory PageOptLinkFunction // category links
}

PageOptLink describes functions to assist with link targets.

type PageOptLinkFunction

type PageOptLinkFunction func(page *Page, ok *bool, target, tooltip, displayDefault *string)

A PageOptLinkFunction sanitizes a link target.

type PageOptNavigation

type PageOptNavigation struct {
	Link    string // link
	Display string // text to display
}

PageOptNavigation represents an ordered navigation item.

type PageOptPage

type PageOptPage struct {
	EnableTitle bool // enable page title headings
	EnableCache bool // enable page caching
}

PageOptPage describes option relating to a page.

type PageOptRoot

type PageOptRoot struct {
	Wiki     string // wiki root path
	Image    string // image root path
	Category string // category root path
	Page     string // page root path
	File     string // file index path
}

PageOptRoot describes HTTP paths to wiki resources.

type PageOptSearch

type PageOptSearch struct {
	Enable bool
}

PageOptSearch describes wiki search options.

Jump to

Keyboard shortcuts

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