Documentation
¶
Index ¶
- Constants
- Variables
- func CreateFolder(db *gorm.DB, parent, name string, user *carrot.User) (string, error)
- func GetTagsByCategory(db *gorm.DB, contentType string, form *TagsForm) ([]string, error)
- func MakeDuplicate(db *gorm.DB, obj any) error
- func MakeMediaPublish(db *gorm.DB, siteID, path, name string, obj any, publish bool) error
- func MakePublish(db *gorm.DB, siteID, ID string, obj any, publish bool) error
- func PrepareStoreLocalDir(db *gorm.DB) (string, error)
- func QueryContentByTags(db *gorm.DB, contentType string, form *QueryByTagsForm) ([]string, error)
- func QueryTags(db *gorm.DB) ([]string, error)
- func RemoveDirectory(db *gorm.DB, path string) (string, error)
- func RemoveFile(db *gorm.DB, path, name string) error
- func SafeDraft(db *gorm.DB, siteID, ID string, obj any, draft string) error
- func StoreExternal(externalUploader, path, name string, data []byte) (string, error)
- func StoreLocal(uploadDir, storePath string, data []byte) (string, error)
- type BaseContent
- type Category
- type CategoryItem
- type CategoryItems
- type ContentIcon
- type ContentQueryResult
- type Media
- type MediaFolder
- type Page
- type Post
- type PublishLog
- type QueryByTagsForm
- type QueryByTagsResult
- type RelationContent
- type RenderCategory
- type RenderContent
- type Site
- type StringArray
- type SummaryResult
- type TagsForm
- type UploadResult
Constants ¶
View Source
const ( ContentTypeHtml = "html" ContentTypeJson = "json" ContentTypeText = "text" ContentTypeMarkdown = "markdown" ContentTypeImage = "image" ContentTypeVideo = "video" ContentTypeAudio = "audio" ContentTypeFile = "file" )
View Source
const ( DefaultCategoryUUIDSize = 12 DefaultPageIDSize = 14 )
View Source
const ENV_CMS_API_PREFIX = "CMS_API_PREFIX"
View Source
const KEY_CMS_API_HOST = "CMS_API_HOST"
View Source
const KEY_CMS_EXTERNAL_UPLOADER = "CMS_EXTERNAL_UPLOADER"
View Source
const KEY_CMS_GUEST_ACCESS_API = "CMS_GUEST_ACCESS_API"
View Source
const KEY_CMS_MEDIA_HOST = "CMS_MEDIA_HOST"
View Source
const KEY_CMS_MEDIA_PREFIX = "CMS_MEDIA_PREFIX"
View Source
const KEY_CMS_RELATION_COUNT = "CMS_RELATION_COUNT"
View Source
const KEY_CMS_SUGGESTION_COUNT = "CMS_SUGGESTION_COUNT"
View Source
const KEY_CMS_UPLOAD_DIR = "CMS_UPLOAD_DIR"
Variables ¶
View Source
var ContentTypes = []carrot.AdminSelectOption{ {Value: ContentTypeJson, Label: "JSON"}, {Value: ContentTypeHtml, Label: "HTML"}, {Value: ContentTypeText, Label: "PlainText"}, {Value: ContentTypeMarkdown, Label: "Markdown"}, {Value: ContentTypeImage, Label: "Image"}, {Value: ContentTypeVideo, Label: "Video"}, {Value: ContentTypeAudio, Label: "Audio"}, {Value: ContentTypeFile, Label: "File"}, }
View Source
var ErrDraftIsInvalid = errors.New("draft is invalid")
View Source
var ErrInvalidPathAndName = errors.New("invalid path and name")
View Source
var ErrPageIsNotPublish = errors.New("page is not publish")
View Source
var ErrPostIsNotPublish = errors.New("post is not publish")
View Source
var ErrUploadsDirNotConfigured = errors.New("uploads dir not configured")
Functions ¶
func CreateFolder ¶
func GetTagsByCategory ¶
Query tags by category
func MakeMediaPublish ¶
func QueryContentByTags ¶
func StoreExternal ¶
Types ¶
type BaseContent ¶
type BaseContent struct {
UpdatedAt time.Time `json:"updatedAt" gorm:"index"`
CreatedAt time.Time `json:"createdAt" gorm:"index"`
Thumbnail string `json:"thumbnail,omitempty" gorm:"size:500"`
Tags string `json:"tags,omitempty" gorm:"size:200;index"`
Title string `json:"title,omitempty" gorm:"size:200"`
Alt string `json:"alt,omitempty"`
Description string `json:"description,omitempty"`
Keywords string `json:"keywords,omitempty"`
CreatorID uint `json:"-"`
Creator carrot.User `json:"-"`
Author string `json:"author" gorm:"size:64"`
Published bool `json:"published"`
PublishedAt sql.NullTime `json:"publishedAt" gorm:"index"`
ContentType string `json:"contentType" gorm:"size:32"`
Remark string `json:"remark"`
}
type Category ¶
type Category struct {
SiteID string `json:"siteId" gorm:"uniqueIndex:,composite:_site_uuid"`
Site Site `json:"-"`
UUID string `json:"uuid" gorm:"size:12;uniqueIndex:,composite:_site_uuid"`
Name string `json:"name" gorm:"size:200"`
Items CategoryItems `json:"items,omitempty"`
Count int `json:"count" gorm:"-"`
}
func QueryCategoryWithCount ¶
func (*Category) FindItem ¶
func (category *Category) FindItem(path string) *CategoryItem
type CategoryItem ¶
type CategoryItem struct {
Path string `json:"path"`
Name string `json:"name"`
Icon *ContentIcon `json:"icon,omitempty"`
Children CategoryItems `json:"children,omitempty"`
Count int `json:"count" gorm:"-"`
}
func (*CategoryItem) Scan ¶
func (s *CategoryItem) Scan(input interface{}) error
type CategoryItems ¶
type CategoryItems []CategoryItem
func (*CategoryItems) Scan ¶
func (s *CategoryItems) Scan(input interface{}) error
type ContentIcon ¶
func (*ContentIcon) Scan ¶
func (s *ContentIcon) Scan(input interface{}) error
type ContentQueryResult ¶
type ContentQueryResult struct {
*carrot.QueryResult
Relations []RelationContent `json:"relations,omitempty"`
Suggestions []RelationContent `json:"suggestions,omitempty"`
}
type Media ¶
type Media struct {
BaseContent
Size int64 `json:"size"`
Directory bool `json:"directory" gorm:"index"`
Path string `json:"path" gorm:"size:200;uniqueIndex:,composite:_path_name"`
Name string `json:"name" gorm:"size:200;uniqueIndex:,composite:_path_name"`
Ext string `json:"ext" gorm:"size:100"`
Dimensions string `json:"dimensions" gorm:"size:200"` // x*y
StorePath string `json:"-" gorm:"size:300"`
External bool `json:"external"`
PublicUrl string `json:"publicUrl,omitempty" gorm:"-"`
}
func (*Media) BuildPublicUrls ¶
type MediaFolder ¶
type MediaFolder struct {
Name string `json:"name"`
Path string `json:"path"`
FilesCount int64 `json:"filesCount"`
FoldersCount int64 `json:"foldersCount"`
}
func ListFolders ¶
func ListFolders(db *gorm.DB, path string) ([]MediaFolder, error)
type Page ¶
type Page struct {
BaseContent
SiteID string `json:"siteId" gorm:"primaryKey;uniqueIndex:,composite:_site_id"`
Site Site `json:"-"`
ID string `json:"id" gorm:"primaryKey;size:100;uniqueIndex:,composite:_site_id"`
IsDraft bool `json:"isDraft"`
Draft string `json:"-"`
Body string `json:"body"`
PreviewURL string `json:"previewUrl,omitempty" gorm:"size:200"`
CategoryID string `json:"categoryId,omitempty" gorm:"size:64;index:,composite:_category_id_path" label:"Category"`
CategoryPath string `json:"categoryPath,omitempty" gorm:"size:64;index:,composite:_category_id_path"`
}
type Post ¶
type Post struct {
BaseContent
SiteID string `json:"siteId" gorm:"primaryKey;uniqueIndex:,composite:_site_id"`
Site Site `json:"-"`
ID string `json:"id" gorm:"primaryKey;size:100;uniqueIndex:,composite:_site_id"`
IsDraft bool `json:"isDraft"`
Draft string `json:"-"`
Body string `json:"body"`
PreviewURL string `json:"previewUrl,omitempty" gorm:"size:200"`
CategoryID string `json:"categoryId,omitempty" gorm:"size:64;index:,composite:_category_id_path" label:"Category"`
CategoryPath string `json:"categoryPath,omitempty" gorm:"size:64;index:,composite:_category_id_path"`
}
type PublishLog ¶
type PublishLog struct {
ID uint `json:"id" gorm:"primarykey"`
CreatedAt time.Time `json:"createdAt"`
AuthorID uint `json:"-"`
Author carrot.User `json:"author"`
Content string `json:"content" gorm:"size:12;index:idx_content_with_id"` // post_id or page_id
ContentID string `json:"contentId" gorm:"size:100;index:idx_content_with_id"` // post_id or page_id
Body string `json:"body"`
}
type QueryByTagsForm ¶
type QueryByTagsResult ¶
type RelationContent ¶
type RelationContent struct {
BaseContent
SiteID string `json:"siteId"`
ID string `json:"id"`
}
func GetRelations ¶
func GetSuggestions ¶
type RenderCategory ¶
type RenderCategory struct {
UUID string `json:"uuid"`
Name string `json:"name"`
Path string `json:"path,omitempty"`
PathName string `json:"pathName,omitempty"`
}
func NewRenderCategory ¶
func NewRenderCategory(db *gorm.DB, categoryID, categoryPath string) *RenderCategory
type RenderContent ¶
type RenderContent struct {
BaseContent
ID string `json:"id"`
SiteID string `json:"siteId"`
Category *RenderCategory `json:"category,omitempty"`
PageData any `json:"data,omitempty"`
PostBody string `json:"body,omitempty"`
IsDraft bool `json:"isDraft"`
Relations []RelationContent `json:"relations,omitempty"`
Suggestions []RelationContent `json:"suggestions,omitempty"`
}
func NewRenderContentFromPage ¶
func NewRenderContentFromPage(db *gorm.DB, page *Page) *RenderContent
func NewRenderContentFromPost ¶
func NewRenderContentFromPost(db *gorm.DB, post *Post, relations bool) *RenderContent
type Site ¶
type StringArray ¶
type StringArray []string
func (*StringArray) Scan ¶
func (s *StringArray) Scan(input interface{}) error
type SummaryResult ¶
type SummaryResult struct {
SiteCount int64 `json:"sites"`
PageCount int64 `json:"pages"`
PostCount int64 `json:"posts"`
CategoryCount int64 `json:"categories"`
MediaCount int64 `json:"media"`
LatestPosts []*RenderContent `json:"latestPosts"`
BuildTime string `json:"buildTime"`
CanExport bool `json:"canExport"`
}
func GetSummary ¶
func GetSummary(db *gorm.DB) (result SummaryResult)
type UploadResult ¶
type UploadResult struct {
PublicUrl string `json:"publicUrl"`
Thumbnail string `json:"thumbnail"`
Path string `json:"path"`
Name string `json:"name"`
External bool `json:"external"`
StorePath string `json:"storePath"`
Dimensions string `json:"dimensions"`
Ext string `json:"ext"`
Size int64 `json:"size"`
ContentType string `json:"contentType"`
}
func UploadFile ¶
Click to show internal directories.
Click to hide internal directories.