post

package
v0.0.0-...-08dd2ef Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAll

func GetAll(conn *sql.DB, isDraft int) (*[]Post, error)

GetAll gets all posts that match a criteria isDraft doesn't look at the is_draft criteria if set to -1, only finds non-drafts if set to 0 and only rafts if set to 1

func GetAllByIds

func GetAllByIds(conn *sql.DB, ids []int) (*[]Post, error)

GetAllByIds gets only the posts with IDs specified

Types

type Post

type Post struct {
	ID             int
	Title          string
	Content        string
	ContentPreview string
	Slug           string
	IsDraft        bool
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

Post contains articles and pages used by the CMS

func Create

func Create(
	conn *sql.DB,
	title string,
	content string,
	slug string,
	isDraft bool,
) (Post, error)

Create inserts a new post to the database

func Delete

func Delete(conn *sql.DB, id int) (Post, error)

Delete removes a post from the database and returns it

func GetByID

func GetByID(conn *sql.DB, id int) (*Post, error)

GetByID returns a single post with the ID specified

func GetBySlug

func GetBySlug(conn *sql.DB, slug string) (*Post, error)

GetBySlug fetches the post from the database by its URL slug

func Update

func Update(
	conn *sql.DB,
	id int,
	title string,
	content string,
	slug string,
	isDraft bool,
) (Post, error)

Update the DB record for a post

func (*Post) GetContentPreview

func (p *Post) GetContentPreview(max int) string

GetContentPreview strips markdown from the content string, trims and returns it

func (*Post) GetHTMLContent

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

GetHTMLContent returns the post's markdown content as HTML

Jump to

Keyboard shortcuts

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