posts

package
v0.0.0-...-d78814b Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: GPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

DB is a reference to the parent app's JsonDB object.

View Source
var (
	ThumbnailImageRegexp = regexp.MustCompile(`['"(]([a-zA-Z0-9-_:/?.=&]+\.(?:jpe?g|png|gif))['")]`)
)

Regexp used to parse a thumbnail image from a blog post. Looks for the first URI component ending with an image extension.

Functions

func UpdateIndex

func UpdateIndex(p *Post) error

UpdateIndex updates a post's metadata in the blog index.

Types

type ByPopularity

type ByPopularity []Tag

ByPopularity sort type.

func (ByPopularity) Len

func (s ByPopularity) Len() int

func (ByPopularity) Less

func (s ByPopularity) Less(i, j int) bool

func (ByPopularity) Swap

func (s ByPopularity) Swap(i, j int)

type ByUpdated

type ByUpdated []Post

ByUpdated sorts blog entries by most recently updated.

func (ByUpdated) Len

func (a ByUpdated) Len() int

func (ByUpdated) Less

func (a ByUpdated) Less(i, j int) bool

func (ByUpdated) Swap

func (a ByUpdated) Swap(i, j int)

type Index

type Index struct {
	Posts      map[int]Post   `json:"posts"`
	Fragments  map[string]int `json:"fragments"`
	Thumbnails map[int]string `json:"thumbnails"`
}

Index caches high level metadata about the blog's contents for fast access.

func GetIndex

func GetIndex() (*Index, error)

GetIndex loads the index, or rebuilds it first if it doesn't exist.

func RebuildIndex

func RebuildIndex() (*Index, error)

RebuildIndex builds the index from scratch.

func (*Index) Delete

func (idx *Index) Delete(p *Post) error

Delete a blog's entry from the index.

func (*Index) Tags

func (idx *Index) Tags() ([]Tag, error)

Tags returns the tags sorted by most frequent.

func (*Index) Update

func (idx *Index) Update(p *Post) error

Update a blog's entry in the index.

type Post

type Post struct {
	ID             int       `json:"id"`
	Title          string    `json:"title"`
	Fragment       string    `json:"fragment"`
	ContentType    string    `json:"contentType,omitempty"`
	AuthorID       int       `json:"author"`
	Body           string    `json:"body,omitempty"`
	Privacy        string    `json:"privacy"`
	Sticky         bool      `json:"sticky"`
	EnableComments bool      `json:"enableComments"`
	Tags           []string  `json:"tags"`
	Created        time.Time `json:"created"`
	Updated        time.Time `json:"updated"`
}

Post holds information for a blog post.

func Load

func Load(id int) (*Post, error)

Load a post by its ID.

func LoadFragment

func LoadFragment(fragment string) (*Post, error)

LoadFragment loads a blog entry by its URL fragment.

func New

func New() *Post

New creates a blank post with sensible defaults.

func (*Post) Delete

func (p *Post) Delete() error

Delete a blog entry.

func (*Post) ExtractThumbnail

func (p *Post) ExtractThumbnail() (string, bool)

ExtractThumbnail searches and returns a thumbnail image to represent the post. This will be the first image embedded in the post, or nothing.

func (*Post) ParseForm

func (p *Post) ParseForm(r *http.Request)

ParseForm populates the post from form values.

func (*Post) Save

func (p *Post) Save() error

Save the blog post.

func (*Post) Validate

func (p *Post) Validate() error

Validate makes sure the required fields are all present.

type Tag

type Tag struct {
	Name  string
	Count int
}

Tag is a response from Tags including metadata about it.

Jump to

Keyboard shortcuts

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