model

package
v0.0.0-...-8fe905f Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TreeIndex is index page tree node
	TreeIndex = "index"
	// TreePost is a post node
	TreePost = "post"
	// TreePage is a page node with content
	TreePage = "page"
	// TreePageNode is a empty page as tree node, not read page
	TreePageNode = "page-node"
	// TreeArchive is node of archive page
	TreeArchive = "archive"
	// TreePostList is node of list page of posts
	TreePostList = "post-list"
	// TreePostTag is node of list posts belongs to a tag
	TreePostTag = "post-tag"
	// TreeTag is node of tag page, no used now
	TreeTag = "tag"
	// TreeXML is xml file node
	TreeXML = "xml"
	// TreeDir is a directory node, use to mark directory
	TreeDir = "dir"
)

Variables

This section is empty.

Functions

func NewPagesFrontMatter

func NewPagesFrontMatter(file string, t FormatType) (map[string]*Page, error)

NewPagesFrontMatter parse page meta file to create page data

func NewPostsFrontMatter

func NewPostsFrontMatter(file string, t FormatType) (map[string]*Post, error)

NewPostsFrontMatter parse post meta file to create post data

func ShouldFormatExtension

func ShouldFormatExtension() map[FormatType]string

ShouldFormatExtension return all extensions of all formats

func ShouldMetaFiles

func ShouldMetaFiles() map[FormatType]string

ShouldMetaFiles return all filenames of meta file in all format

func ShouldPageMetaFiles

func ShouldPageMetaFiles() map[FormatType]string

ShouldPageMetaFiles return all filenames of meta file for pages

func ShouldPostMetaFiles

func ShouldPostMetaFiles() map[FormatType]string

ShouldPostMetaFiles return all filenames of meta file for posts

func ShouldThemeMetaFiles

func ShouldThemeMetaFiles() map[FormatType]string

ShouldThemeMetaFiles return all filenames of meta file for theme

Types

type Analytics

type Analytics struct {
	Google string `toml:"google" ini:"google"`
	Baidu  string `toml:"baidu" ini:"baidu"`
	Cnzz   string `toml:"cnzz" ini:"cnzz"`
}

Analytics save unique values for web analytics service

type Archive

type Archive struct {
	Year  int // each list by year
	Posts []*Post
}

Archive is archive set for posts

type Archives

type Archives struct {
	Data []*Archive
	// contains filtered or unexported fields
}

Archives is collection of all archive sets

func NewArchive

func NewArchive(posts []*Post) Archives

NewArchive converts posts to archive

func (*Archives) DestURL

func (a *Archives) DestURL() string

DestURL return the file that archives compile into

func (*Archives) SetDestURL

func (a *Archives) SetDestURL(url string)

SetDestURL set destURL for archives

type Author

type Author struct {
	Name    string `toml:"name" ini:"name"`
	Nick    string `toml:"nick" ini:"nick"`
	Email   string `toml:"email" ini:"email"`
	URL     string `toml:"url" ini:"url"`
	Avatar  string `toml:"avatar" ini:"avatar"`
	Bio     string `toml:"bio" ini:"bio"`
	Repo    string `toml:"repo" ini:"repo"` // github repository
	IsOwner bool   // must be the first author
}

Author is author item in meta file

type AuthorGroup

type AuthorGroup []*Author

AuthorGroup is collection of Authors

type Build

type Build struct {
	DisablePost bool `toml:"disable_post" ini:"disable_post"`
	DisablePage bool `toml:"disable_page" ini:"disable_page"`

	PostDir      string `toml:"post_dir" ini:"post_dir"`
	PageDir      string `toml:"page_dir" ini:"page_dir"`
	LangDir      string `toml:"lang_dir" ini:"lang_dir"`
	MediaDir     string `toml:"media_dir" ini:"media_dir"`
	PostPageSize int    `toml:"post_pagesize" ini:"post_pagesize"`
}

Build is settings for builder in meta file

type Comment

type Comment struct {
	Disqus  string `toml:"disqus" ini:"disqus"`
	Duoshuo string `toml:"duoshuo" ini:"duoshuo"`
}

Comment save unique values for third-party comment systems

func (*Comment) IsOK

func (c *Comment) IsOK() bool

IsOK return the comment setting is valid

type FormatType

type FormatType int8

FormatType define type of front-matter format, meta file and language file

const (
	// FormatTOML mean toml format
	FormatTOML FormatType = 1
	// FormatINI mean ini format
	FormatINI FormatType = 2
)

type JSON

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

JSON simple reader struct

func NewJSON

func NewJSON(data []byte) *JSON

NewJSON create JSON struct with json bytes

func NewJSONwithResult

func NewJSONwithResult(res gjson.Result) *JSON

NewJSONwithResult create JSON struct with parsed json result

func (*JSON) Bool

func (j *JSON) Bool(path ...string) bool

Bool get bool value by path

func (*JSON) Exist

func (j *JSON) Exist(path ...string) bool

Exist check existing of value by path

func (*JSON) Float

func (j *JSON) Float(path ...string) float64

Float is alias of float64

func (*JSON) Float32

func (j *JSON) Float32(path ...string) float32

Float32 get float32 value by path

func (*JSON) Float64

func (j *JSON) Float64(path ...string) float64

Float64 get float64 value by path

func (*JSON) Floats

func (j *JSON) Floats(path ...string) []float64

Floats get float64 slice by path

func (*JSON) Get

func (j *JSON) Get(path ...string) *JSON

Get return a json struct to operation this json node

func (*JSON) Index

func (j *JSON) Index(i int) *JSON

Index get item of slice by index if current JSON is an array, otherwise return nil

func (*JSON) Int

func (j *JSON) Int(path ...string) int

Int get int value by path

func (*JSON) Int16

func (j *JSON) Int16(path ...string) int16

Int16 get int16 value by path

func (*JSON) Int32

func (j *JSON) Int32(path ...string) int32

Int32 get int32 value by path

func (*JSON) Int64

func (j *JSON) Int64(path ...string) int64

Int64 get int64 value by path

func (*JSON) Int8

func (j *JSON) Int8(path ...string) int8

Int8 get int8 value by path

func (*JSON) Ints

func (j *JSON) Ints(path ...string) []int64

Ints get int64 slice by path

func (*JSON) Key

func (j *JSON) Key(key string) *JSON

Key get JSON struct by key if current JSON is map

func (*JSON) Map

func (j *JSON) Map(path ...string) map[string]*JSON

Map get map of JSON by path

func (*JSON) Slice

func (j *JSON) Slice(path ...string) []*JSON

Slice get JSON struct slice by path

func (*JSON) String

func (j *JSON) String(path ...string) string

String get string value by path string

func (*JSON) Strings

func (j *JSON) Strings(path ...string) []string

Strings get string slice by path

type Meta

type Meta struct {
	Title    string `toml:"title" ini:"title"`
	Subtitle string `toml:"subtitle" ini:"subtitle"`
	Keyword  string `toml:"keyword" ini:"keyword"`
	Desc     string `toml:"desc" ini:"desc"`
	Domain   string `toml:"domain" ini:"domain"`
	Root     string `toml:"root" ini:"root"`
	Cover    string `toml:"cover" ini:"cover"`
	Language string `toml:"lang" ini:"lang"`
	Path     string `toml:"-" ini:"-"`
}

Meta is meta info of website

func (*Meta) DomainURL

func (m *Meta) DomainURL(link string) string

DomainURL return link with domain prefix

type MetaAll

type MetaAll struct {
	Meta        *Meta       `toml:"meta"`
	NavGroup    NavGroup    `toml:"nav"`
	AuthorGroup AuthorGroup `toml:"author"`
	Comment     *Comment    `toml:"comment"`
	Analytics   *Analytics  `toml:"analytics"`
	Build       *Build      `toml:"build"`
}

MetaAll is all data struct in meta file

func NewMetaAll

func NewMetaAll(data []byte, format FormatType) (*MetaAll, error)

NewMetaAll parse bytes with correct FormatType

func (*MetaAll) Normalize

func (ma *MetaAll) Normalize() error

Normalize make meta all data correct, it fills blank fields to correct values

type Nav struct {
	Link        string `toml:"link" ini:"link"`
	Title       string `toml:"title" ini:"title"`
	OriginTitle string `toml:"-" ini:"-"`
	IsBlank     bool   `toml:"blank" ini:"blank"`
	Icon        string `toml:"icon" ini:"icon"`
	Hover       string `toml:"hover" ini:"hover"`
	I18n        string `toml:"i18n" ini:"i18n"`
	IsRemote    bool   `toml:"-" ini:"-"`
}

Nav is item of navigation

func (n *Nav) Tr(i18n *helper.I18n) string

Tr print nav title with i18n helper

func (n *Nav) TrLink(i18n *helper.I18n) string

TrLink print nav link with i18n prefix

func (n *Nav) TrTitle(i18n *helper.I18n) string

TrTitle print nav title with i18n value. If i18n="", use Nav.Title

type NavGroup []*Nav

NavGroup is group if items of navigation

func (ng NavGroup) SetPrefix(prefix string)

SetPrefix fix url path of all navigation items with prefix

type Page

type Page struct {
	Title      string                 `toml:"title" ini:"title"`
	Slug       string                 `toml:"slug" ini:"slug"`
	Desc       string                 `toml:"desc" ini:"desc"`
	Date       string                 `toml:"date" ini:"date"`
	Update     string                 `toml:"update_date" ini:"update_date"`
	AuthorName string                 `toml:"author" ini:"author"`
	NavHover   string                 `toml:"hover" ini:"hover"`
	Template   string                 `toml:"template" ini:"template"`
	Lang       string                 `toml:"lang" ini:"lang"`
	Bytes      []byte                 `toml:"-"`
	Meta       map[string]interface{} `toml:"meta" ini:"-"`
	Sort       int                    `toml:"sort" ini:"sort"`
	Author     *Author                `toml:"-" ini:"-"`
	Draft      bool                   `toml:"draft" ini:"draft"`
	Node       bool                   `toml:"node" ini:"node"`
	JSONFile   string                 `toml:"json" ini:"json"`
	JSON       *JSON                  `toml:"-" ini:"-"`
	Index      []*PostIndex           `toml:"-" ini:"-"`
	// contains filtered or unexported fields
}

Page contain all fields of a page content

func NewPageOfMarkdown

func NewPageOfMarkdown(file, slug string, page *Page) (*Page, error)

NewPageOfMarkdown create new page from markdown file

func (*Page) Content

func (p *Page) Content() []byte

Content is page's content bytes

func (*Page) ContentHTML

func (p *Page) ContentHTML() template.HTML

ContentHTML is page's content html

func (*Page) Created

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

Created get create time

func (*Page) DestURL

func (p *Page) DestURL() string

DestURL is dest url of node

func (*Page) IsUpdated

func (p *Page) IsUpdated() bool

IsUpdated return true if updated time is not same to created time

func (*Page) LoadJSON

func (p *Page) LoadJSON(dir string) error

LoadJSON load json if the file is setting

func (*Page) SetDestURL

func (p *Page) SetDestURL(url string)

SetDestURL set path when assemble posts

func (*Page) SetPlaceholder

func (p *Page) SetPlaceholder(htmlReplacer *strings.Replacer)

SetPlaceholder fix @placeholder in post values

func (*Page) SetURL

func (p *Page) SetURL(url string)

SetURL set path when assemble posts

func (*Page) SourceURL

func (p *Page) SourceURL() string

SourceURL get source file path of the page

func (*Page) URL

func (p *Page) URL() string

URL is page's url

func (*Page) Updated

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

Updated get update time

type PagerPosts

type PagerPosts struct {
	Posts
	Pager *helper.Pager

	URL string
	// contains filtered or unexported fields
}

PagerPosts are list of posts by pagination

func (*PagerPosts) DestURL

func (pp *PagerPosts) DestURL() string

DestURL return compile file name of paged post list

func (*PagerPosts) SetDestURL

func (pp *PagerPosts) SetDestURL(url string)

SetDestURL set destUrl to paged post list

type Pages

type Pages []*Page

Pages means pages list

func (Pages) BySlug

func (p Pages) BySlug(slug string) *Page

BySlug return a page by slug string

type Post

type Post struct {
	Title      string       `toml:"title" ini:"title"`
	Slug       string       `toml:"slug" ini:"slug"`
	Desc       string       `toml:"desc" ini:"desc"`
	Date       string       `toml:"date" ini:"date"`
	Update     string       `toml:"update_date" ini:"update_date"`
	AuthorName string       `toml:"author" ini:"author"`
	Thumb      string       `toml:"thumb" ini:"thumb"`
	Draft      bool         `toml:"draft" ini:"draft"`
	TagString  []string     `toml:"tags" ini:"-"`
	Tags       []*Tag       `toml:"-" ini:"-"`
	Author     *Author      `toml:"-" ini:"-"`
	Index      []*PostIndex `toml:"-" ini:"-"`

	Bytes []byte `toml:"-"`
	// contains filtered or unexported fields
}

Post contain all fields of a post content

func NewPostOfMarkdown

func NewPostOfMarkdown(file string, post *Post) (*Post, error)

NewPostOfMarkdown create new post from markdown file

func (*Post) Brief

func (p *Post) Brief() []byte

Brief get brief content bytes

func (*Post) BriefHTML

func (p *Post) BriefHTML() template.HTML

BriefHTML get brief html content

func (*Post) Content

func (p *Post) Content() []byte

Content get html content bytes

func (*Post) ContentHTML

func (p *Post) ContentHTML() template.HTML

ContentHTML get html content

func (*Post) Created

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

Created get create time

func (*Post) DestURL

func (p *Post) DestURL() string

DestURL get destination file of the post after compiled

func (*Post) IsUpdated

func (p *Post) IsUpdated() bool

IsUpdated return true if updated time is not same to created time

func (*Post) Preview

func (p *Post) Preview() []byte

Preview get brief html content deprecated

func (*Post) PreviewHTML

func (p *Post) PreviewHTML() template.HTML

PreviewHTML get brief html content deprecated

func (*Post) SetDestURL

func (p *Post) SetDestURL(url string)

SetDestURL set dest-url

func (*Post) SetPlaceholder

func (p *Post) SetPlaceholder(stringReplacer, htmlReplacer *strings.Replacer)

SetPlaceholder fix @placeholder in post values

func (*Post) SetURL

func (p *Post) SetURL(url string)

SetURL set path when assemble posts

func (*Post) SourceURL

func (p *Post) SourceURL() string

SourceURL get source file path of the post

func (*Post) URL

func (p *Post) URL() string

URL get url of the post

func (*Post) Updated

func (p *Post) Updated() time.Time

Updated get update time

type PostIndex

type PostIndex struct {
	Level    int
	Title    string
	Archor   string
	Children []*PostIndex
	Link     string
	Parent   *PostIndex
}

PostIndex is index of post

func (*PostIndex) Print

func (p *PostIndex) Print()

Print prints post indexs friendly

type Posts

type Posts []*Post

Posts are posts list

func (Posts) Len

func (p Posts) Len() int

implement sort.Sort interface

func (Posts) Less

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

func (Posts) Range

func (p Posts) Range(i, j int) Posts

Range get ranged[i:j] posts from list

func (Posts) Swap

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

func (Posts) TopN

func (p Posts) TopN(i int) Posts

TopN get top N posts from list

type Tag

type Tag struct {
	Name string
	URL  string
}

Tag is tag struct of post

func NewTag

func NewTag(name string) *Tag

NewTag returns new Tag with name and proper url

type TagPosts

type TagPosts struct {
	Posts
	Tag *Tag
	// contains filtered or unexported fields
}

TagPosts are list of posts belongs to a tag

func (*TagPosts) DestURL

func (tp *TagPosts) DestURL() string

DestURL return compile file name of tag post list

func (*TagPosts) SetDestURL

func (tp *TagPosts) SetDestURL(url string)

SetDestURL set destUrl to tag post list

type Tree

type Tree struct {
	Title string
	Link  string
	I18n  string
	Type  string
	Sort  int
	Dest  string
	URL   string
	// contains filtered or unexported fields
}

Tree describe the position of one file in all compiled files

func NewTree

func NewTree(dest string) *Tree

NewTree create new tree node records with dest prefix string

func (*Tree) Add

func (t *Tree) Add(link, title, linkType string, s int)

Add add tree node

func (*Tree) Child

func (t *Tree) Child(link ...string) *Tree

Child return the node by link, if not exist, return nil

func (*Tree) Children

func (t *Tree) Children(link ...string) []*Tree

Children return nodes of tree by url link in next child level, not all chilrens in all levels

func (*Tree) Dirs

func (t *Tree) Dirs(link ...string) []*Tree

Dirs returns nodes of dir nodes by link

func (*Tree) FullURL

func (t *Tree) FullURL() string

FullURL return full url of this node from top

func (*Tree) HasChildren

func (t *Tree) HasChildren() bool

HasChildren return true if Tree's children is not empty

func (*Tree) IsValid

func (t *Tree) IsValid() bool

IsValid return whether the node is compiled or not

func (*Tree) Nodes

func (t *Tree) Nodes(link ...string) []*Tree

Nodes return nodes of page-node by link

func (*Tree) Pages

func (t *Tree) Pages(link ...string) []*Tree

Pages return nodes of page by link

func (*Tree) Parent

func (t *Tree) Parent() *Tree

Parent return parent node of this node

func (*Tree) Parents

func (t *Tree) Parents() []*Tree

Parents return all parents of the node, begin at top

func (*Tree) Posts

func (t *Tree) Posts(link ...string) []*Tree

Posts return nodes of post by link

func (*Tree) Print

func (t *Tree) Print(prefix string)

Print print tree nodes as readable string

Jump to

Keyboard shortcuts

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