wiki

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: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CategoryTypeImage is a type of category that tracks which pages use an image.
	CategoryTypeImage CategoryType = "image"

	// CategoryTypeModel is a type of category that tracks which pages use a model.
	CategoryTypeModel = "model"

	// CategoryTypePage is a type of category that tracks which pages reference another page.
	CategoryTypePage = "page"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {

	// category path
	Path string `json:"-"`

	// category filename, including the .cat extension
	File string `json:"-"`

	// category name without extension
	Name string `json:"name,omitempty"`

	// human-readable category title
	Title string `json:"title,omitempty"`

	// time when the category was created
	Created     *time.Time `json:"created,omitempty"`
	CreatedHTTP string     `json:"created_http,omitempty"` // HTTP formatted

	// time when the category was last modified.
	// this is updated when pages are added and deleted
	Modified     *time.Time `json:"modified,omitempty"`
	ModifiedHTTP string     `json:"modified_http,omitempty"` // HTTP formatted

	// pages in the category. keys are filenames
	Pages map[string]CategoryEntry `json:"pages,omitempty"`

	// when true, the category is preserved even when no pages remain
	Preserve bool `json:"preserve,omitempty"`

	// if applicable, this is the type of special category.
	// for normal categories, this is empty
	Type CategoryType `json:"type,omitempty"`

	// for CategoryTypePage, this is the info for the tracked page
	PageInfo *wikifier.PageInfo `json:"page_info,omitempty"`

	// for CategoryTypeImage, this is the info for the tracked image
	ImageInfo *struct {
		Width  int `json:"width,omitempty"`
		Height int `json:"height,omitempty"`
	} `json:"image_info,omitempty"`
}

A Category is a collection of pages pertaining to a topic.

A page can belong to many categories. Category memberships and metadta are stored in JSON manifests.

func (*Category) AddPage

func (cat *Category) AddPage(w *Wiki, page *wikifier.Page)

AddPage adds a page to a category.

If the page already belongs and any information has changed, the category is updated. If force is true,

func (*Category) Exists

func (cat *Category) Exists() bool

Exists returns whether a category currently exists.

type CategoryEntry

type CategoryEntry struct {

	// time at which the page metadata in this category file was last updated.
	// this is compared against page file modification time
	Asof *time.Time `json:"asof,omitempty"`

	// embedded page info
	// note this info is accurate only as of the Asof time
	wikifier.PageInfo

	// for CategoryTypeImage, an array of image dimensions used on this page.
	// dimensions are guaranteed to be positive integers. the number of elements will
	// always be even, since each occurrence of the image produces two (width and then height)
	Dimensions [][]int `json:"dimensions,omitempty"`

	// for CategoryTypePage, an array of line numbers on which the tracked page is
	// referenced on the page described by this entry
	Lines []int `json:"lines,omitempty"`
}

A CategoryEntry describes a page that belongs to a category.

type CategoryInfo

type CategoryInfo struct {
	File     string     `json:"file"`               // filename
	Created  *time.Time `json:"created,omitempty"`  // creation time
	Modified *time.Time `json:"modified,omitempty"` // modify time
}

CategoryInfo represents metadata associated with a category.

type CategoryType

type CategoryType string

CategoryType describes the type of a Category.

type DisplayCategoryPosts

type DisplayCategoryPosts struct {

	// DisplayPage results
	// overrides the Category Pages field
	Pages []DisplayPage `json:"pages,omitempty"`

	// the page number (first page = 0)
	PageN int `json:"page_n"`

	// the total number of pages
	NumPages int `json:"num_pages"`

	// this is the combined CSS for all pages we're displaying
	CSS string `json:"css,omitempty"`

	// all other fields are inherited from the category itself
	*Category
}

DisplayCategoryPosts represents a category result to display.

type DisplayError

type DisplayError struct {
	// a human-readable error string. sensitive info is never
	// included, so this may be shown to users
	Error string

	// a more detailed human-readable error string that MAY contain
	// sensitive data. can be used for debugging and logging but should
	// not be presented to users
	DetailedError string

	// HTTP status code. if zero, 404 should be used
	Status int

	// true if the error occurred during parsing
	ParseError bool

	// true if the content cannot be displayed because it has
	// not yet been published for public access
	Draft bool
}

DisplayError represents an error result to display.

type DisplayFile

type DisplayFile struct {

	// file name relative to wiki root.
	// path delimiter '/' is always used, regardless of OS.
	File string `json:"file,omitempty"`

	// absolute file path of the file.
	// OS-specific path delimiter is used.
	Path string `json:"path,omitempty"`

	// the plain text file content
	Content string

	// time when the file was last modified
	Modified *time.Time `json:"modified,omitempty"`
}

DisplayFile represents a plain text file to display.

type DisplayImage

type DisplayImage struct {

	// basename of the scaled image file
	File string `json:"file,omitempty"`

	// absolute path to the scaled image.
	// this file should be served to the user
	Path string `json:"path,omitempty"`

	// absolute path to the full-size image.
	// if the full-size image is being displayed, same as Path
	FullsizePath string `json:"fullsize_path,omitempty"`

	// image type
	// 'png' or 'jpeg'
	ImageType string `json:"image_type,omitempty"`

	// mime 'image/png' or 'image/jpeg'
	// suitable for the Content-Type header
	Mime string `json:"mime,omitempty"`

	// bytelength of image data
	// suitable for use in the Content-Length header
	Length int64 `json:"length,omitempty"`

	// time when the image was last modified.
	// if Generated is true, this is the current time.
	// if FromCache is true, this is the modified date of the cache file.
	// otherwise, this is the modified date of the image file itself.
	Modified     *time.Time `json:"modified,omitempty"`
	ModifiedHTTP string     `json:"modified_http,omitempty"` // HTTP format for Last-Modified

	// true if the content being sered was read from a cache file.
	// opposite of Generated
	FromCache bool `json:"cached,omitempty"`

	// true if the content being served was just generated.
	// opposite of FromCache
	Generated bool `json:"generated,omitempty"`

	// true if the content generated in order to fulfill this request was
	// written to cache. this can only been true when Generated is true
	CacheGenerated bool `json:"cache_gen,omitempty"`
}

DisplayImage represents an image to display.

type DisplayPage

type DisplayPage struct {

	// basename of the page, with the extension
	File string `json:"file,omitempty"`

	// basename of the page, without the extension
	Name string `json:"name,omitempty"`

	// absolute file path of the page
	Path string `json:"path,omitempty"`

	// the page content (HTML)
	Content wikifier.HTML `json:"content,omitempty"`

	// time when the page was last modified.
	// if Generated is true, this is the current time.
	// if FromCache is true, this is the modified date of the cache file.
	// otherwise, this is the modified date of the page file itself.
	Modified     *time.Time `json:"modified,omitempty"`
	ModifiedHTTP string     `json:"modified_http,omitempty"` // HTTP formatted for Last-Modified

	// CSS generated for the page from style{} blocks
	CSS string `json:"css,omitempty"`

	// true if this content was read from a cache file. opposite of Generated
	FromCache bool `json:"cached,omitempty"`

	// true if the content being served was just generated on the fly.
	// opposite of FromCache
	Generated bool `json:"generated,omitempty"`

	// true if this request resulted in the writing of a new cache file.
	// this can only be true if Generated is true
	CacheGenerated bool `json:"cache_gen,omitempty"`

	// true if this request resulted in the writing of a text file.
	// this can only be true if Generated is true
	TextGenerated bool `json:"text_gen,omitempty"`

	// true if the page has not yet been published for public viewing.
	// this only occurs when it is specified that serving drafts is OK,
	// since normally a draft page instead results in a DisplayError.
	Draft bool `json:"draft,omitempty"`

	// warnings produced by the parser
	Warnings []string `json:"warnings,omitempty"`

	// time when the page was created, as extracted from
	// the special @page.created variable
	Created     *time.Time `json:"created,omitempty"`
	CreatedHTTP string     `json:"created_http,omitempty"` // HTTP formatted

	// name of the page author, as extracted from the special @page.author
	// variable
	Author string `json:"author,omitempty"`

	// list of categories the page belongs to, without the '.cat' extension
	Categories []string `json:"categories,omitempty"`

	// page title as extracted from the special @page.title variable, including
	// any possible HTML-encoded formatting
	FmtTitle wikifier.HTML `json:"fmt_title,omitempty"`

	// like FmtTitle except that all text formatting has been stripped.
	// suitable for use in the <title> tag
	Title string `json:"title,omitempty"`
}

DisplayPage represents a page result to display.

type DisplayRedirect

type DisplayRedirect struct {

	// a relative or absolute URL to which the request should redirect,
	// suitable for use in a Location header
	Redirect string
}

DisplayRedirect represents a page redirect to follow.

type ImageInfo

type ImageInfo struct {
	File       string     `json:"file"`               // filename
	Width      int        `json:"width,omitempty"`    // full-size width
	Height     int        `json:"height,omitempty"`   // full-size height
	Created    *time.Time `json:"created,omitempty"`  // creation time
	Modified   *time.Time `json:"modified,omitempty"` // modify time
	Dimensions [][]int    `json:"-"`                  // dimensions used throughout the wiki
}

ImageInfo represents a full-size image on the wiki.

type ModelInfo

type ModelInfo struct {
	File     string     `json:"file"` // filename
	Path     string     `json:"path"`
	Created  *time.Time `json:"created,omitempty"`  // creation time
	Modified *time.Time `json:"modified,omitempty"` // modify time
}

ModelInfo represents metadata associated with a model.

type SizedImage

type SizedImage struct {
	// for example 100x200-myimage@3x.png
	Width, Height int    // 100, 200 (dimensions as requested)
	Scale         int    // 3 (scale as requested)
	Name          string // myimage (name without extension)
	Ext           string // png (extension)
	// contains filtered or unexported fields
}

SizedImage represents an image in specific dimensions.

func SizedImageFromName

func SizedImageFromName(name string) SizedImage

SizedImageFromName returns a SizedImage given an image name.

func (SizedImage) FullName

func (img SizedImage) FullName() string

FullName returns the image name with true dimensions.

func (SizedImage) FullNameNE

func (img SizedImage) FullNameNE() string

FullNameNE is like FullName but without the extension.

func (SizedImage) FullSizeName

func (img SizedImage) FullSizeName() string

FullSizeName returns the name of the full-size image.

func (SizedImage) ScaleName

func (img SizedImage) ScaleName() string

ScaleName returns the image name with dimensions and scale.

func (SizedImage) TrueHeight

func (img SizedImage) TrueHeight() int

TrueHeight returns the actual image height when the Scale is taken into consideration.

func (SizedImage) TrueWidth

func (img SizedImage) TrueWidth() int

TrueWidth returns the actual image width when the Scale is taken into consideration.

type Wiki

type Wiki struct {
	ConfigFile        string
	PrivateConfigFile string
	Opt               wikifier.PageOpt
	Auth              *authenticator.Authenticator
	// contains filtered or unexported fields
}

A Wiki represents a quiki website.

func NewWiki

func NewWiki(conf, privateConf string) (*Wiki, error)

NewWiki creates a Wiki given the public and private configuration files.

func (*Wiki) Branches

func (w *Wiki) Branches() ([]string, error)

Branches returns the git branches available.

func (*Wiki) Categories

func (w *Wiki) Categories() []CategoryInfo

Categories returns info about all the models in the wiki.

func (*Wiki) CategoryInfo

func (w *Wiki) CategoryInfo(name string) (info CategoryInfo)

CategoryInfo is an inexpensive request for info on a category.

func (*Wiki) CategoryMap

func (w *Wiki) CategoryMap() map[string]CategoryInfo

CategoryMap returns a map of model name to CategoryInfo for all models in the wiki.

func (*Wiki) DisplayCategoryPosts

func (w *Wiki) DisplayCategoryPosts(catName string, pageN int) interface{}

DisplayCategoryPosts returns the display result for a category.

func (*Wiki) DisplayFile

func (w *Wiki) DisplayFile(path string) interface{}

DisplayFile returns the display result for a plain text file.

func (*Wiki) DisplayImage

func (w *Wiki) DisplayImage(name string) interface{}

DisplayImage returns the display result for an image.

func (*Wiki) DisplayPage

func (w *Wiki) DisplayPage(name string) interface{}

DisplayPage returns the display result for a page.

func (*Wiki) DisplayPageDraft

func (w *Wiki) DisplayPageDraft(name string, draftOK bool) interface{}

DisplayPageDraft returns the display result for a page.

Unlike DisplayPage, if draftOK is true, the content is served even if it is marked as draft.

func (*Wiki) DisplaySizedImage

func (w *Wiki) DisplaySizedImage(img SizedImage) interface{}

DisplaySizedImage returns the display result for an image in specific dimensions.

func (*Wiki) DisplaySizedImageGenerate

func (w *Wiki) DisplaySizedImageGenerate(img SizedImage, generateOK bool) interface{}

DisplaySizedImageGenerate returns the display result for an image in specific dimensions and allows images to be generated in any dimension.

func (*Wiki) FindPage

func (w *Wiki) FindPage(name string) (p *wikifier.Page)

FindPage attempts to find a page on this wiki given its name, regardless of the file format or filename case.

If a page by this name exists, the returned page represents it. Otherwise, a new page representing the lowercased, normalized .page file is returned in the standard quiki filename format.

func (*Wiki) GetCategory

func (w *Wiki) GetCategory(name string) *Category

GetCategory loads or creates a category.

func (*Wiki) GetSpecialCategory

func (w *Wiki) GetSpecialCategory(name string, typ CategoryType) *Category

GetSpecialCategory loads or creates a special category given the type.

func (*Wiki) ImageInfo

func (w *Wiki) ImageInfo(name string) (info ImageInfo)

ImageInfo returns info for an image given its full-size name.

func (*Wiki) ImageMap

func (w *Wiki) ImageMap() map[string]ImageInfo

ImageMap returns a map of image filename to ImageInfo for all images in the wiki.

func (*Wiki) Images

func (w *Wiki) Images() []ImageInfo

Images returns info about all the images in the wiki.

func (*Wiki) ModelInfo

func (w *Wiki) ModelInfo(name string) (info ModelInfo)

ModelInfo is an inexpensive request for info on a model. It uses cached metadata rather than generating the model and extracting variables.

func (*Wiki) ModelMap

func (w *Wiki) ModelMap() map[string]ModelInfo

ModelMap returns a map of model name to ModelInfo for all models in the wiki.

func (*Wiki) Models

func (w *Wiki) Models() []ModelInfo

Models returns info about all the models in the wiki.

func (*Wiki) PageInfo

func (w *Wiki) PageInfo(name string) (info wikifier.PageInfo)

PageInfo is an inexpensive request for info on a page. It uses cached metadata rather than generating the page and extracting variables.

func (*Wiki) PageMap

func (w *Wiki) PageMap() map[string]wikifier.PageInfo

PageMap returns a map of page name to PageInfo for all pages in the wiki.

func (*Wiki) Pages

func (w *Wiki) Pages() []wikifier.PageInfo

Pages returns info about all the pages in the wiki.

func (*Wiki) Pregenerate

func (w *Wiki) Pregenerate()

Pregenerate simulates requests for all wiki resources such that content caches can be pregenerated and stored.

Jump to

Keyboard shortcuts

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