goblog

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2020 License: MIT Imports: 12 Imported by: 0

README

goblog

A simple framework for dropping blogging functionality into a website.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func URLSafeSlug

func URLSafeSlug(input string) string

Types

type Handler

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

func NewHandler

func NewHandler(m Manager, pe ParamExtractor) Handler

func (Handler) AddPost

func (h Handler) AddPost(w http.ResponseWriter, r *http.Request)

func (Handler) AddTag

func (h Handler) AddTag(w http.ResponseWriter, r *http.Request)

func (Handler) AddTagToPost

func (h Handler) AddTagToPost(w http.ResponseWriter, r *http.Request)

func (Handler) GetPost

func (h Handler) GetPost(w http.ResponseWriter, r *http.Request)

func (Handler) GetTag added in v0.3.0

func (h Handler) GetTag(w http.ResponseWriter, r *http.Request)

func (Handler) GetTagWithPosts

func (h Handler) GetTagWithPosts(w http.ResponseWriter, r *http.Request)

func (Handler) ListPosts

func (h Handler) ListPosts(w http.ResponseWriter, r *http.Request)

func (Handler) ListTags

func (h Handler) ListTags(w http.ResponseWriter, r *http.Request)

func (Handler) RegisterRoutes

func (h Handler) RegisterRoutes(mux *chi.Mux)

RegisterRoutes takes a mux, should be a sub router with the desired auth middleware attached All of these routes are intended to be secure as they are for authoring of the posts.

func (Handler) RemoveTagFromPost

func (h Handler) RemoveTagFromPost(w http.ResponseWriter, r *http.Request)

func (Handler) ToggleActive

func (h Handler) ToggleActive(w http.ResponseWriter, r *http.Request)

func (Handler) ToggleFeatured

func (h Handler) ToggleFeatured(w http.ResponseWriter, r *http.Request)

func (Handler) UpdatePost

func (h Handler) UpdatePost(w http.ResponseWriter, r *http.Request)

func (Handler) UpdateTag added in v0.3.0

func (h Handler) UpdateTag(w http.ResponseWriter, r *http.Request)

type Manager

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

func NewManager

func NewManager(orm *gorm.DB) Manager

func (Manager) AddTagToPost

func (m Manager) AddTagToPost(pid, tid string) error

func (Manager) GetPost

func (m Manager) GetPost(pid string) (Post, error)

func (Manager) GetPostWithSlug

func (m Manager) GetPostWithSlug(slug string) (Post, error)

func (Manager) GetTagWithPosts

func (m Manager) GetTagWithPosts(tid string, limit, offset int) (Tag, error)

func (Manager) ListActiveFeaturedPosts

func (m Manager) ListActiveFeaturedPosts() ([]Post, error)

func (Manager) ListActivePosts

func (m Manager) ListActivePosts(limit, offset int) ([]Post, error)

func (Manager) ListPosts

func (m Manager) ListPosts(limit, offset int) ([]Post, error)

func (Manager) ListSlugUpdatedActive

func (m Manager) ListSlugUpdatedActive() ([]Post, error)

func (Manager) ListTags

func (m Manager) ListTags() ([]Tag, error)

func (Manager) NewPost

func (m Manager) NewPost(r io.Reader) (Post, error)

func (Manager) NewTag

func (m Manager) NewTag(r io.Reader) (Tag, error)

func (Manager) PageActivePosts

func (m Manager) PageActivePosts(limit, page int) ([]Post, Paginator, error)

func (Manager) RemoveTagFromPost

func (m Manager) RemoveTagFromPost(pid, tid string) error

func (Manager) ToggleActive

func (m Manager) ToggleActive(pid string) error

func (Manager) ToggleFeatured

func (m Manager) ToggleFeatured(pid string) error

func (Manager) UpdatePost

func (m Manager) UpdatePost(r io.Reader) error

func (Manager) UpdateTag added in v0.3.0

func (m Manager) UpdateTag(r io.Reader) error

type Paginator

type Paginator struct {
	HasMore  bool `json:"hasMore"`
	MorePage int  `json:"morePage"`
	HasLess  bool `json:"hasLess"`
	LessPage int  `json:"lessPage"`
}

type ParamExtractor

type ParamExtractor func(r *http.Request, name string) string

type Post

type Post struct {
	ID          string     `gorm:"type:varchar(48)" json:"id"`
	CreatedAt   time.Time  `json:"createdAt"`
	UpdatedAt   time.Time  `json:"updatedAt"`
	DeletedAt   *time.Time `sql:"index" json:",omitempty"`
	Title       string     `json:"title" gorm:"type:varchar(2048)"`
	Slug        string     `json:"slug" gorm:"index:idx_slug;type:varchar(2048)"`
	Body        string     `json:"body" gorm:"type:text"`
	Description string     `json:"description" gorm:"type:text"`
	Featured    bool       `json:"featured"`
	Active      bool       `json:"active"`
	AuthorID    string     `json:"authorId" gorm:"type:varchar(1024)"`
	Tags        []*Tag     `gorm:"many2many:post_tags;" json:"tags"`
	Cover       string     `json:"cover" gorm:"type:varchar(2048)"`
	CoverAlt    string     `json:"coverAlt" gorm:"type:text"`

	OgURL              string `json:"ogurl"`
	OgTitle            string `json:"ogtitle"`
	OgDescription      string `json:"ogdescription"`
	OgImage            string `json:"ogimage"`
	OgImageType        string `json:"ogimagetype"`
	OgImageWidth       string `json:"ogimagewidth"`
	OgImageHeight      string `json:"ogimageheight"`
	FbAppID            string `json:"fbappid"`
	OgType             string `json:"ogtype"`
	OgLocale           string `json:"oglocale"`
	TwitterCard        string `json:"twittercard"`
	TwitterSite        string `json:"twittersite"`
	TwitterTitle       string `json:"twittertitle"`
	TwitterDescription string `json:"twitterdescription"`
	TwitterCreator     string `json:"twittercreator"`
	TwitterImage       string `json:"twitterimage"`
}

func (*Post) BeforeCreate

func (p *Post) BeforeCreate(scope *gorm.DB) error

func (*Post) BeforeUpdate

func (p *Post) BeforeUpdate(scope *gorm.DB) error

func (Post) GetDescription

func (p Post) GetDescription(def string) string

GetDescription returns page description, intended to be called from the template with a default value

func (Post) GetFbAppId

func (p Post) GetFbAppId(def string) string

GetFbAppId returns the fb app id or the default value passed in

func (Post) GetOgDescription

func (p Post) GetOgDescription(def string) string

GetOgDescription returns the open graph description, the regular description, or the default value passed in

func (Post) GetOgImage

func (p Post) GetOgImage(def string) string

GetOgImage returns the open graph image or the default value passed in

func (Post) GetOgLocale

func (p Post) GetOgLocale() string

GetOgLocale returns the open graph locale or the default locale

func (Post) GetOgTitle

func (p Post) GetOgTitle(def string) string

GetOgTitle returns the open graph title for the page, or the regular title, or the default value passed in

func (Post) GetOgType

func (p Post) GetOgType() string

GetOgType returns the open graph type or the default website

func (Post) GetOgUrl

func (p Post) GetOgUrl(def string) string

GetOgUrl returns the open graph url or the canonical url

func (Post) GetTitle

func (p Post) GetTitle(def string) string

GetTitle returns the page title, intended to be called from the template with a default value

func (Post) GetTwitterCard

func (p Post) GetTwitterCard(def string) string

GetTwitterCard returns the twitter card summary

func (Post) GetTwitterCreator

func (p Post) GetTwitterCreator(def string) string

GetTwitterCreator returns the twitter creator or default

func (Post) GetTwitterDescription

func (p Post) GetTwitterDescription(def string) string

GetTwitterDescription returns the twitter description or the page description or the default

func (Post) GetTwitterImage

func (p Post) GetTwitterImage(def string) string

GetTwitterImage returns the twitter image or default

func (Post) GetTwitterSite

func (p Post) GetTwitterSite(def string) string

GetTwitterSite returns the twitter site or default. i.e. @KendellFab

func (Post) GetTwitterTitle

func (p Post) GetTwitterTitle(def string) string

GetTwitterTitle returns the twitter title or the page title or the default

type Tag

type Tag struct {
	ID        string     `gorm:"type:varchar(48)" json:"id"`
	CreatedAt time.Time  `json:"createdAt"`
	UpdatedAt time.Time  `json:"updatedAt"`
	DeletedAt *time.Time `sql:"index" json:",omitempty"`
	Title     string     `json:"title"`
	Slug      string     `json:"slug"`
	Body      string     `json:"body"`
	Posts     []*Post    `gorm:"many2many:post_tags;"`
	Cover     string     `json:"cover" gorm:"type:varchar(2048)"`
	CoverAlt  string     `json:"coverAlt" gorm:"type:text"`
}

func (*Tag) BeforeCreate

func (t *Tag) BeforeCreate(scope *gorm.DB) error

func (*Tag) BeforeUpdate

func (t *Tag) BeforeUpdate(scope *gorm.DB) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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