cms

package
v0.0.0-...-29f5810 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cms contains types and specialized functions for working with these.

Index

Constants

This section is empty.

Variables

ContentTypes is a list of available types.

Functions

func AllUsers

func AllUsers(col *mgo.Collection, query interface{}) (items []*user.User, err error)

AllUsers returns all users from a database.

func GetAuthorsForContent

func GetAuthorsForContent(db *mgo.Database, c *Content) (err error)

GetAuthorsForContent fetches authors for the provided content.

func GetChildrenContent

func GetChildrenContent(db *mgo.Database, c *Content) (err error)

GetChildrenContent finds all dependent content and updates the parent.

func GetTopicsForContent

func GetTopicsForContent(db *mgo.Database, c *Content) (err error)

GetTopicsForContent retrieves content from the database by .TopicIDs.

Types

type Content

type Content struct {
	ID bson.ObjectId `bson:"_id"`
	// Weight is the priority of the content. The bigger is more important.
	Weight int
	// Public shows if the content is public or not.
	Public bool
	// Promoted helps to define special content, which should be treated specially.
	Promoted bool
	// Page indicates if that piece of content is a separate page.
	// TODO: must be changed for ContentType Page. Update: orgsite, infocenter.
	Page bool
	// Language is two-letter language code of a content's language.
	// https://docs.mongodb.com/manual/tutorial/specify-language-for-text-index/#specify-default-language-text-index
	// two letter code: http://docs.mongodb.org/manual/reference/text-search-languages/#text-search-languages
	Language string

	// LanguageOverride is used for "be". We use .Language attribute in the UI and for searching and navigating
	// content. So we can't specify "none" value for .Language field for mongodb to be fine and not throwing
	// "language override unsupported be" error. So, use .LanguageOverride attribute to set it to "none" for "be" materials.
	LanguageOverride string `bson:"language_override,omitempty"`

	// Type represents a content's type.
	Type ContentType
	// Slug is a transliterated title and is used for URL composition and resultion.
	Slug string

	Created   time.Time
	Updated   time.Time
	Scheduled time.Time
	Published time.Time

	// Page meta information.
	PageSlug        string
	PageTitle       string
	PageDescription string

	// ParentID is used to specifye the parent content.
	ParentID *bson.ObjectId
	// Children contains all dependent content which has .ID as .ParentID in itself.
	Children []*Content `bson:"-"`

	// TopicIDs specifies to which topics this content belongs.
	// For this application we restrict the amount of topics to one
	// so that we can use the only topic to generate a unique URL
	// for a piece of content.
	TopicIDs []bson.ObjectId
	Topics   []*Topic `bson:"-"` // do not store in database

	// AuthorIDs specifies authors of the content.
	AuthorIDs []bson.ObjectId
	Authors   []*user.User `bson:"-"` // do not store in database

	Title string
	Lede  string
	Body  string

	// TODO: URL to external resources must be forbidden
	// CoverExternal is displayed at index pages.
	CoverExternal string
	// CoverInternal is displayed at the material page.
	CoverInternal string

	Images []struct {
		URL, Caption, LinkTo, Credits string // TODO: finish with Credits
	}

	// EventStart is a field for events.
	EventStart time.Time
	Location   string

	// LinkTo is a field for banners. It stores a URL to redirect to after clicking.
	LinkTo string

	// Payload is use for additional structured data.
	Payload map[string]interface{}
}

Content represents a piece of content which belongs to one or several topics and one or several authors.

func AllContent

func AllContent(db *mgo.Database, query interface{}) (items []*Content, err error)

AllContent returns all content from a database.

func AllContentByPage

func AllContentByPage(col *mgo.Collection, query interface{}, perpage, page int) (items []*Content, prev, next int, err error)

AllContentByPage returns content items by page.

func AllContentLimited

func AllContentLimited(db *mgo.Database, query interface{}, limit int) (items []*Content, err error)

AllContentLimited returns limited amount of content from a database.

func AllContentSorted

func AllContentSorted(db *mgo.Database, query interface{}, sortField string) (items []*Content, err error)

AllContentSorted returns all content from a database sorted by the specified field: "-eventstart" or "eventstart".

func SearchContent

func SearchContent(db *mgo.Database, query interface{}, limit int) (items []*Content, err error)

SearchContent matches the query only for the Content collection. It sorts results by the mongo score.

type ContentType

type ContentType int

ContentType is used to differentiate content of a website to display each content differently.

const (
	// Article represents a text article.
	Article ContentType = iota
	Banner
	// Audio represents podcast or other audio content.
	Audio
	// Video represents video content.
	Video
	// Page is a page.
	Page
	// Event is an event.
	Event

	// ArticleSeries is used to group several articles into a group of articles.
	ArticleSeries

	// Research is like a longread or a simple article but with different subtype
	// to differentiate between simple posts.
	Research

	// Photoreport is an article with photographs as main content.
	Photoreport
)

func (ContentType) String

func (t ContentType) String() string

type Message

type Message struct {
	ID       bson.ObjectId `bson:"_id"`
	Created  time.Time
	Status   MessageStatus
	FullName string
	Email    mail.Address
	Message  string
}

Message represents a message from a website user.

type MessageStatus

type MessageStatus int

MessageStatus represents a message status in the CMS.

const (
	// New means a message is fresh and unprocessed.
	New MessageStatus = iota
	// InWork means a message is being processed.
	InWork
	// Closed means a message is no longer needs attention.
	Closed
)

type Topic

type Topic struct {
	ID     bson.ObjectId `bson:"_id"`
	Title  string
	Weight int
	Public bool
	Page   bool

	// Slug is a transliterated title and is used for URL composition and resolution.
	Slug string

	// https://docs.mongodb.com/manual/tutorial/specify-language-for-text-index/#specify-default-language-text-index
	Language string
	// LanguageOverride is used for "be". We use .Language attribute in the UI and for searching and navigating
	// content. So we can't specify "none" value for .Language field for mongodb to be fine and not throwing
	// "language override unsupported be" error. So, use .LanguageOverride attribute to set it to "none" for "be" materials.
	LanguageOverride string `bson:"language_override,omitempty"`
}

Topic represents a section of content grouped by a theme.

func AllTopics

func AllTopics(db *mgo.Database, query interface{}) ([]*Topic, error)

AllTopics returs topics sorted by weight.

func GetTopic

func GetTopic(db *mgo.Database, idStr string) (*Topic, error)

GetTopic returst a single topic by ID.

Jump to

Keyboard shortcuts

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