Documentation ¶
Index ¶
- Constants
- Variables
- func AutoMigrate(b *Builder, db *gorm.DB) (err error)
- func EditSetterFunc(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) (err error)
- func GetOpenGraphMetadataString(metadata []OpenGraphMetadata) string
- func SeoJSComponentsPack() web.ComponentsPack
- type Builder
- func (b *Builder) AfterSave(v func(ctx context.Context, settingName string, locale string) error) *Builder
- func (b *Builder) AutoMigrate() (r *Builder)
- func (b *Builder) BatchRender(objs interface{}, req *http.Request) []h.HTMLComponent
- func (b *Builder) EditingComponentFunc(obj interface{}, _ *presets.FieldContext, ctx *web.EventContext) h.HTMLComponent
- func (b *Builder) GetGlobalSEO() *SEO
- func (b *Builder) GetSEO(obj interface{}) *SEO
- func (b *Builder) GetSEOPriority(name string) int
- func (b *Builder) Install(pb *presets.Builder) error
- func (b *Builder) ModelInstall(pb *presets.Builder, mb *presets.ModelBuilder) error
- func (b *Builder) RegisterSEO(name string, model ...interface{}) *SEO
- func (b *Builder) RemoveSEO(obj interface{}) *Builder
- func (b *Builder) Render(obj interface{}, req *http.Request) h.HTMLComponent
- func (b *Builder) SortSEOs(SEOs []*QorSEOSetting)
- type ContextVarFunc
- type Messages
- type NonModelSEO
- type OpenGraphMetadata
- type Option
- type QorSEOSetting
- type SEO
- func (seo *SEO) AppendChildren(children ...*SEO) *SEO
- func (seo *SEO) GetName() string
- func (seo *SEO) RegisterContextVariable(varName string, varFunc ContextVarFunc) *SEO
- func (seo *SEO) RegisterMetaProperty(propName string, propFunc ContextVarFunc) *SEO
- func (seo *SEO) RegisterSettingVariables(names ...string) *SEO
- func (seo *SEO) SetParent(newParent *SEO) *SEO
- type Setting
- type VSeoBuilder
- func (b *VSeoBuilder) AppendChildren(children ...h.HTMLComponent) (r *VSeoBuilder)
- func (b *VSeoBuilder) Attr(vs ...interface{}) (r *VSeoBuilder)
- func (b *VSeoBuilder) Children(children ...h.HTMLComponent) (r *VSeoBuilder)
- func (b *VSeoBuilder) Class(names ...string) (r *VSeoBuilder)
- func (b *VSeoBuilder) ClassIf(name string, add bool) (r *VSeoBuilder)
- func (b *VSeoBuilder) MarshalHTML(ctx context.Context) (r []byte, err error)
- func (b *VSeoBuilder) Placeholder(v string) (r *VSeoBuilder)
- func (b *VSeoBuilder) PrependChildren(children ...h.HTMLComponent) (r *VSeoBuilder)
- func (b *VSeoBuilder) SetAttr(k string, v interface{})
- func (b *VSeoBuilder) Value(v string) (r *VSeoBuilder)
- type Variables
Constants ¶
const ( I18nSeoKey i18n.ModuleKey = "I18nSeoKey" SeoDetailFieldName = "SEO" )
const (
PermEdit = "perm_seo_edit"
)
Variables ¶
var Messages_en_US = &Messages{
Variable: "Variables Setting",
Basic: "Basic",
Title: "Title",
Description: "Description",
Keywords: "Keywords",
OpenGraphInformation: "Open Graph Information",
OpenGraphTitle: "Open Graph Title",
OpenGraphDescription: "Open Graph Description",
OpenGraphURL: "Open Graph URL",
OpenGraphType: "Open Graph Type",
OpenGraphImageURL: "Open Graph Image URL",
OpenGraphImage: "Open Graph Image",
OpenGraphMetadata: "Open Graph Metadata",
Seo: "SEO",
Customize: "Customize",
SEOPreview: "SEO Preview",
}
var Messages_zh_CN = &Messages{
Variable: "变量设置",
Basic: "基本信息",
Title: "标题",
Description: "描述",
Keywords: "关键词",
OpenGraphInformation: "OG 信息",
OpenGraphTitle: "OG 标题",
OpenGraphDescription: "OG 描述",
OpenGraphURL: "OG 链接",
OpenGraphType: "OG 类型",
OpenGraphImageURL: "OG 图片链接",
OpenGraphImage: "OG 图片",
OpenGraphMetadata: "OG 元数据",
Seo: "搜索引擎优化",
Customize: "自定义",
SEOPreview: "SEO 预览",
}
Functions ¶
func EditSetterFunc ¶
func EditSetterFunc(obj interface{}, field *presets.FieldContext, ctx *web.EventContext) (err error)
func GetOpenGraphMetadataString ¶
func GetOpenGraphMetadataString(metadata []OpenGraphMetadata) string
func SeoJSComponentsPack ¶
func SeoJSComponentsPack() web.ComponentsPack
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder will hold registered SEO configures and global setting definition and other configures @snippet_begin(SeoBuilderDefinition)
func (*Builder) AfterSave ¶
func (b *Builder) AfterSave(v func(ctx context.Context, settingName string, locale string) error) *Builder
AfterSave sets the hook called after saving
func (*Builder) AutoMigrate ¶ added in v3.0.2
func (*Builder) BatchRender ¶
func (b *Builder) BatchRender(objs interface{}, req *http.Request) []h.HTMLComponent
BatchRender rendering multiple SEOs at once. objs must be a slice, and each element in objs must be of the same type. It is the responsibility of the caller to ensure that every element in objs is of the same type, as it is performance-intensive to check whether each element in `objs` if of the same type through reflection.
If you want to render non-model SEO, you must pass a slice of NonModelSEO to objs. For convenience, you can call NewNonModelSEOSlice function to create a slice of NonModelSEO. For Example: Following code will render the non-model SEO named "About Us" with locale "en" and "zh". b.BatchRender(NewNonModelSEOSlice("About Us", "en", "zh"))
func (*Builder) EditingComponentFunc ¶
func (b *Builder) EditingComponentFunc(obj interface{}, _ *presets.FieldContext, ctx *web.EventContext) h.HTMLComponent
func (*Builder) GetGlobalSEO ¶
func (*Builder) GetSEO ¶
GetSEO retrieves the specified SEO, It accepts two types of parameters. One is a string, where the literal value of the parameter is the name of the SEO. The other is an instance of a struct that has a field of type `Setting`, in which case the SEO corresponding to the type of the struct will be returned.
func (*Builder) GetSEOPriority ¶
GetSEOPriority gets the priority of the specified SEO, with higher number indicating higher priority. The priority of Global SEO is 1 (the lowest priority)
func (*Builder) ModelInstall ¶ added in v3.0.1
func (*Builder) RegisterSEO ¶
RegisterSEO registers a SEO through name or model. There are two types of SEOs, one is SEO with model, the other is SEO without model aka 'non-model seo'. if you want to register a non-model SEO, you can call RegisterSEO method like this: seoBuilder.RegisterSEO("About Us") if you want to register a SEO with model, you can call RegisterSEO method like this: seoBuilder.RegisterSEO("Product", &Product{}) the first parameter of RegisterSEO method is the name of the SEO, it will be displayed in the admin user interface.
If the SEO to be registered already exists, it will panic. The optional second parameter names `model` is an instance of a type that has a field of type `Setting`, if the type of model does not have such field or len(model) > 1, the program will panic.
The default parent of the registered SEO is global seo. If you need to set its parent, Please call the SetParent method of SEO after invoking RegisterSEO method. For Example: b.RegisterSEO("Region", &Region{}).SetParent(parentSEO) Or you can call appendChild method to add the SEO to the specified parent. For Example: b.GetGlobalSEO().appendChild(b.RegisterSEO("Region", &Region{}))
func (*Builder) RemoveSEO ¶
RemoveSEO removes the specified SEO, if the SEO has children, the parent of the children will be the parent of the SEO
func (*Builder) Render ¶
func (b *Builder) Render(obj interface{}, req *http.Request) h.HTMLComponent
Render renders the SEO according to the specified object. obj must be of type NonModelSEO or a pointer to a struct that has a field of type `Setting`.
If the obj is an instance of NonModelSEO, it will render the non-model SEO. For Example: following code will render the non-model SEO named "About Us" with locale "en". b.render(NewNonModelSEO("About Us", "en"))
When the locales passed to New method is only one, you can call NewNonModelSEO without passing the locale parameter. in this case, the only locale passed to New method will be used. For Example: following code will render the non-model SEO named "About Us" with locale "en". b := New(db, []string{"en"}) b.Render(NewNonModelSEO("About Us"))
func (*Builder) SortSEOs ¶
func (b *Builder) SortSEOs(SEOs []*QorSEOSetting)
SortSEOs sorts the SEOs in the order of their priority. The global SEO is always the first element in the sorted slice.
type Messages ¶
type Messages struct { Variable string VariableDescription string Basic string Title string Description string Keywords string OpenGraphInformation string OpenGraphTitle string OpenGraphDescription string OpenGraphURL string OpenGraphType string OpenGraphImageURL string OpenGraphImage string OpenGraphMetadata string Seo string Customize string SEOPreview string }
type NonModelSEO ¶
type NonModelSEO interface { GetName() string l10n.LocaleInterface }
NonModelSEO is used to store the name and locale of non-model SEO. If you register a SEO without model like the following: b.RegisterSEO("About Us") When you want to render the SEO, you must pass a NonModelSEO instance to Render method. For Example: b.Render(NewNonModelSEO("About Us", "en")) or b.render(NewNonModelSEO("About Us")) when the locales passed to New method is only one.
func NewNonModelSEO ¶
func NewNonModelSEO(name string, locale ...string) NonModelSEO
NewNonModelSEO creates a nonModelSEO instance that implements NonModelSEO interface. This function is only used to create a NonModelSEO instance passed to Render method. the name parameter must be the same as the name you passed to RegisterSEO method. For Example: If you register a SEO like this: b.RegisterSEO("About Us"), when you want render "About US" SEO, you must pass "About Us" to NewNonModelSEO method like this: b := New(db, []string{"en", "zh"}) b.Render(NewNonModelSEO("About Us", "en")).
For convenience, you can call NewNonModelSEO function without passing the locale parameter when the locales passed to New method is only one. For Example: b := newBuilder(db, []string{"en"}) // only one locale(en) is passed to New method. b.render(NewNonModelSEO("About Us")) // the only locale(en) passed to New method will be used.
func NewNonModelSEOSlice ¶
func NewNonModelSEOSlice(name string, locales ...string) []NonModelSEO
NewNonModelSEOSlice creates a slice of NonModelSEO. The function is only used to create a slice of NonModelSEO passed to BatchRender method. For Example: following code will render the non-model SEO named "About Us" with locale "en" and "zh". b.BatchRender(NewNonModelSEOSlice("About Us", "en", "zh"))
type OpenGraphMetadata ¶
OpenGraphMetadata open graph meta data
func GetOpenGraphMetadata ¶
func GetOpenGraphMetadata(in string) (metadata []OpenGraphMetadata)
type Option ¶
type Option func(*Builder)
func WithGlobalSEOName ¶
func WithInherit ¶
func WithLocales ¶
type QorSEOSetting ¶
type QorSEOSetting struct { Name string `gorm:"primaryKey"` Setting Setting Variables Variables `sql:"type:text"` CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time `gorm:"index"` l10n.Locale }
func (*QorSEOSetting) PrimaryColumnValuesBySlug ¶
func (s *QorSEOSetting) PrimaryColumnValuesBySlug(slug string) map[string]string
func (*QorSEOSetting) PrimarySlug ¶
func (s *QorSEOSetting) PrimarySlug() string
type SEO ¶
type SEO struct {
// contains filtered or unexported fields
}
SEO represents a SEO object for a page @snippet_begin(SeoDefinition)
func (*SEO) AppendChildren ¶
AppendChildren sets the parent of each child in the children to the current SEO. Usage: builder.RegisterSEO(parent).AppendChildren(
builder.RegisterSEO(child1), builder.RegisterSEO(child2), builder.RegisterSEO(child3)
) Or: builder.RegisterSEO(parent).AppendChildren(
builder.RegisterMultipleSEO(child1, child2, child3)...
)
func (*SEO) RegisterContextVariable ¶
func (seo *SEO) RegisterContextVariable(varName string, varFunc ContextVarFunc) *SEO
func (*SEO) RegisterMetaProperty ¶
func (seo *SEO) RegisterMetaProperty(propName string, propFunc ContextVarFunc) *SEO
func (*SEO) RegisterSettingVariables ¶
type Setting ¶
type Setting struct { Title string `gorm:"size:4294967295" json:",omitempty"` Description string `json:",omitempty"` Keywords string `json:",omitempty"` OpenGraphTitle string `json:",omitempty"` OpenGraphDescription string `json:",omitempty"` OpenGraphURL string `json:",omitempty"` OpenGraphType string `json:",omitempty"` OpenGraphImageURL string `json:",omitempty"` OpenGraphImageFromMediaLibrary media_library.MediaBox `json:",omitempty"` OpenGraphMetadata []OpenGraphMetadata `json:",omitempty"` EnabledCustomize bool `json:",omitempty"` }
Setting defined meta's attributes
func (*Setting) HTMLComponent ¶
func (setting *Setting) HTMLComponent(metaProperties map[string]string) h.HTMLComponent
type VSeoBuilder ¶
type VSeoBuilder struct {
// contains filtered or unexported fields
}
func VSeo ¶
func VSeo(children ...h.HTMLComponent) (r *VSeoBuilder)
func (*VSeoBuilder) AppendChildren ¶
func (b *VSeoBuilder) AppendChildren(children ...h.HTMLComponent) (r *VSeoBuilder)
func (*VSeoBuilder) Attr ¶
func (b *VSeoBuilder) Attr(vs ...interface{}) (r *VSeoBuilder)
func (*VSeoBuilder) Children ¶
func (b *VSeoBuilder) Children(children ...h.HTMLComponent) (r *VSeoBuilder)
func (*VSeoBuilder) Class ¶
func (b *VSeoBuilder) Class(names ...string) (r *VSeoBuilder)
func (*VSeoBuilder) ClassIf ¶
func (b *VSeoBuilder) ClassIf(name string, add bool) (r *VSeoBuilder)
func (*VSeoBuilder) MarshalHTML ¶
func (b *VSeoBuilder) MarshalHTML(ctx context.Context) (r []byte, err error)
func (*VSeoBuilder) Placeholder ¶
func (b *VSeoBuilder) Placeholder(v string) (r *VSeoBuilder)
func (*VSeoBuilder) PrependChildren ¶
func (b *VSeoBuilder) PrependChildren(children ...h.HTMLComponent) (r *VSeoBuilder)
func (*VSeoBuilder) SetAttr ¶
func (b *VSeoBuilder) SetAttr(k string, v interface{})
func (*VSeoBuilder) Value ¶
func (b *VSeoBuilder) Value(v string) (r *VSeoBuilder)