category

package
v0.0.0-...-28009d5 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package category supports post categories

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("category doesn't exist")
)

Functions

func HashtagFromTitle

func HashtagFromTitle(title string) string

HashtagFromTitle generates a valid single-word, camelCase hashtag from a title (which might include spaces, punctuation, etc.).

Types

type Category

type Category struct {
	ID        int64  `json:"-"`
	Hashtag   string `json:"hashtag"`
	Slug      string `json:"slug"`
	Title     string `json:"title"`
	PostCount int64  `json:"post_count"`

	// IsCategory distinguishes this Category from a mere tag. If true, it is often prominently featured on a blog,
	// and looked up via its Slug instead of its Hashtag. It usually has all metadata, such as Title, correctly
	// populated.
	IsCategory bool `json:"-"`
}

Category represents a post tag with additional metadata, like a title and slug.

func NewCategory

func NewCategory(hashtag string) *Category

NewCategory creates a Category you can insert into the database, based on a hashtag. It automatically breaks up the hashtag by words, based on capitalization, for both the title and a URL-friendly slug.

func NewCategoryFromPartial

func NewCategoryFromPartial(cat *Category) *Category

NewCategoryFromPartial creates a Category from a partially-populated Category, such as when a user initially creates one.

Jump to

Keyboard shortcuts

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