seo

package
v0.0.0-...-73c3907 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: MIT Imports: 25 Imported by: 0

README

SEO

The SEO library allows for the management and injection of dynamic data into HTML tags for the purpose of Search Engine Optimisation.

Usage

  • Create a SEO collection
// Create a collection and register global seo by default
collection := seo.NewCollection()

// Change the default global name
collection.SetGlobalName("My Global SEO")

// Change the default context db key
collection.SetDBContextKey("My DB")

// Change the default seo model setting
type MySEOSetting struct{
  QorSEOSetting
  publish
  l10n
}
collection.SetSettingModel(&MySEOSetting{})

// Turn off the default inherit the upper level SEO data when the current SEO data is missing
collection.SetInherited(false)

  • Register and remove SEO
// Register mutiple SEO by name
collection.RegisterSEOByNames("Not Found", "Internal Server Error")

// Register a SEO by model
type Product struct{
  Name  string
  Setting Setting
}
collection.RegisterSEO(&Product{})

// Remove a SEO
collection.RemoveSEO(&Product{}).RemoveSEO("Not Found")
  • Configure SEO
// Change the default SEO name when register a SEO by model

collection.RegisterSEO(&Product{}).SetName("My Product")

// Register a context Variable
collection.RegisterSEO(&Product{}).
          RegisterContextVariables("og:image", func(obj interface{}, _ *Setting, _ *http.Request) string {
						return obj.image.url
					}).
          RegisterContextVariables("Name", func(obj interface{}, _ *Setting, _ *http.Request) string {
						return obj.Name
					})


// Register setting variable
collection.RegisterSEO(&Product{}).
          RegisterSettingVaribles(struct{ProductTag string}{})
  • Render SEO html data
// Render Global SEO
collection.RenderGlobal(request)

// Render SEO by a name
collection.Render("product", request)

// Render SEO by a model
collection.Render(Product{}, request)

Documentation

Index

Constants

View Source
const (
	I18nSeoKey i18n.ModuleKey = "I18nSeoKey"
)
View Source
const (
	PermEdit = "perm_seo_edit"
)

Variables

View Source
var (
	GlobalSEO    = "Global SEO"
	GlobalDB     *gorm.DB
	DBContextKey contextKey = "DB"
)
View Source
var Messages_en_US = &Messages{
	PageTitle:               "SEO Setting",
	Variable:                "Variables Setting",
	PageMetadataTitle:       "Page Metadata Defaults",
	PageMetadataDescription: "These defaults are for pages automatically generated by the system, you can override them on the individual pages.",
	Basic:                   "Basic",
	Title:                   "Title",
	Description:             "Description",
	Keywords:                "Keywords",
	OpenGraphInformation:    "Open Graph Information",
	OpenGraphURL:            "Open Graph URL",
	OpenGraphType:           "Open Graph Type",
	OpenGraphImageURL:       "Open Graph Image URL",
	OpenGraphImage:          "Open Graph Image",
	Save:                    "Save",
	SavedSuccessfully:       "Saved successfully",
	Seo:                     "SEO",
	UseDefaults:             "Use Defaults",
	GlobalName:              "Global Default SEO",
}
View Source
var Messages_zh_CN = &Messages{
	PageTitle:               "搜索引擎优化设置",
	Variable:                "变量设置",
	PageMetadataTitle:       "页面默认值",
	PageMetadataDescription: "这些默认值适用于系统自动生成的页面,您可以在各个页面上覆盖它们。",
	Basic:                   "基本信息",
	Title:                   "标题",
	Description:             "描述",
	Keywords:                "关键词",
	OpenGraphInformation:    "OG 信息",
	OpenGraphURL:            "OG 链接",
	OpenGraphType:           "OG 类型",
	OpenGraphImageURL:       "OG 图片链接",
	OpenGraphImage:          "OG 图片",
	Save:                    "保存",
	SavedSuccessfully:       "成功保存",
	Seo:                     "搜索引擎优化",
	UseDefaults:             "使用默认值",
	GlobalName:              "全局默认SEO",
}

Functions

func ContextWithDB

func ContextWithDB(ctx context.Context, db *gorm.DB) context.Context

func SeoJSComponentsPack

func SeoJSComponentsPack() web.ComponentsPack

Types

type Collection

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

Collection will hold registered seo configures and global setting definition and other configures @snippet_begin(SeoCollectionDefinition)

func NewCollection

func NewCollection() *Collection

Create a SeoCollection instance

func (*Collection) Configure

func (collection *Collection) Configure(b *presets.Builder, db *gorm.DB)

func (*Collection) GetSEO

func (collection *Collection) GetSEO(obj interface{}) *SEO

GetSEO get a Seo

func (*Collection) GetSEOByModel

func (collection *Collection) GetSEOByModel(model interface{}) *SEO

GetSEOByModel get a seo by model

func (*Collection) GetSEOByName

func (collection *Collection) GetSEOByName(name string) *SEO

GetSEO get a Seo by name

func (*Collection) NewSettingModelInstance

func (collection *Collection) NewSettingModelInstance() interface{}

func (*Collection) NewSettingModelSlice

func (collection *Collection) NewSettingModelSlice() interface{}

func (*Collection) RegisterSEO

func (collection *Collection) RegisterSEO(obj interface{}) (seo *SEO)

RegisterSEO register a seo

func (*Collection) RegisterSEOByNames

func (collection *Collection) RegisterSEOByNames(names ...string) *Collection

RegisterSEOByNames register mutiple seo by names

func (*Collection) RemoveSEO

func (collection *Collection) RemoveSEO(obj interface{}) *Collection

RegisterSEO remove a seo

func (Collection) Render

func (collection Collection) Render(obj interface{}, req *http.Request) h.HTMLComponent

Render render seo tags

func (Collection) RenderGlobal

func (collection Collection) RenderGlobal(req *http.Request) h.HTMLComponent

RenderGlobal render global seo

func (*Collection) SetDBContextKey

func (collection *Collection) SetDBContextKey(key interface{}) *Collection

RegisterDBContextKey register a key to get db from context

func (*Collection) SetGlobalName

func (collection *Collection) SetGlobalName(name string) *Collection

func (*Collection) SetInherited

func (collection *Collection) SetInherited(b bool) *Collection

RegisterVariblesSetting register variables setting

func (*Collection) SetSettingModel

func (collection *Collection) SetSettingModel(s interface{}) *Collection

RegisterVariblesSetting register variables setting

type Messages

type Messages struct {
	PageTitle               string
	Variable                string
	VariableDescription     string
	PageMetadataTitle       string
	PageMetadataDescription string
	Basic                   string
	Title                   string
	Description             string
	Keywords                string
	OpenGraphInformation    string
	OpenGraphURL            string
	OpenGraphType           string
	OpenGraphImageURL       string
	OpenGraphImage          string
	Save                    string
	SavedSuccessfully       string
	Seo                     string
	UseDefaults             string
	GlobalName              string
}

type OpenGraphMetadata

type OpenGraphMetadata struct {
	Property string
	Content  string
}

OpenGraphMetadata open graph meta data

type QorSEOSetting

type QorSEOSetting struct {
	Name      string `gorm:"primary_key"`
	Setting   Setting
	Variables Variables `sql:"type:text"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time `gorm:"index"`
}

QorSEOSetting default seo model

func (QorSEOSetting) GetDescription

func (s QorSEOSetting) GetDescription() string

GetDescription get Setting's description

func (QorSEOSetting) GetKeywords

func (s QorSEOSetting) GetKeywords() string

GetKeywords get Setting's keywords

func (QorSEOSetting) GetName

func (s QorSEOSetting) GetName() string

GetName get QorSeoSetting's name

func (QorSEOSetting) GetOpenGraphImageFromMediaLibrary

func (s QorSEOSetting) GetOpenGraphImageFromMediaLibrary() media_library.MediaBox

func (QorSEOSetting) GetOpenGraphImageURL

func (s QorSEOSetting) GetOpenGraphImageURL() string

func (QorSEOSetting) GetOpenGraphMetadata

func (s QorSEOSetting) GetOpenGraphMetadata() []OpenGraphMetadata

func (QorSEOSetting) GetOpenGraphType

func (s QorSEOSetting) GetOpenGraphType() string

func (QorSEOSetting) GetOpenGraphURL

func (s QorSEOSetting) GetOpenGraphURL() string

func (QorSEOSetting) GetSEOSetting

func (s QorSEOSetting) GetSEOSetting() Setting

GetSEOSetting get seo setting

func (QorSEOSetting) GetTitle

func (s QorSEOSetting) GetTitle() string

GetTitle get Setting's title

func (QorSEOSetting) GetVariables

func (s QorSEOSetting) GetVariables() Variables

GetVariablesSetting get variables setting

func (*QorSEOSetting) SetName

func (s *QorSEOSetting) SetName(name string)

SetName set QorSeoSetting's name

func (*QorSEOSetting) SetSEOSetting

func (s *QorSEOSetting) SetSEOSetting(setting Setting)

func (*QorSEOSetting) SetVariables

func (s *QorSEOSetting) SetVariables(setting Variables)

SetVariablesSetting set variables setting

type QorSEOSettingInterface

type QorSEOSettingInterface interface {
	GetName() string
	SetName(string)
	GetSEOSetting() Setting
	SetSEOSetting(Setting)
	GetVariables() Variables
	SetVariables(Variables)
	GetTitle() string
	GetDescription() string
	GetKeywords() string
	GetOpenGraphURL() string
	GetOpenGraphType() string
	GetOpenGraphImageURL() string
	GetOpenGraphImageFromMediaLibrary() media_library.MediaBox
	GetOpenGraphMetadata() []OpenGraphMetadata
}

QorSEOSettingInterface support customize Seo model @snippet_begin(QorSEOSettingInterface)

type SEO

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

SEO represents a seo object for a page @snippet_begin(SeoDefinition)

func (*SEO) RegisterContextVariables

func (seo *SEO) RegisterContextVariables(key string, f contextVariablesFunc) *SEO

RegisterContextVariables register context variables

func (*SEO) RegisterSettingVaribles

func (seo *SEO) RegisterSettingVaribles(setting interface{}) *SEO

RegisterSettingVaribles register a setting variable

func (*SEO) SetModel

func (seo *SEO) SetModel(model interface{}) *SEO

RegisterModel register a model to seo

func (*SEO) SetName

func (seo *SEO) SetName(name string) *SEO

SetName set seo name

type Setting

type Setting struct {
	Title                          string `gorm:"size:4294967295"`
	Description                    string
	Keywords                       string
	OpenGraphURL                   string
	OpenGraphType                  string
	OpenGraphImageURL              string
	OpenGraphImageFromMediaLibrary media_library.MediaBox
	OpenGraphMetadata              []OpenGraphMetadata
	EnabledCustomize               bool
}

Setting defined meta's attributes

func (Setting) HTMLComponent

func (setting Setting) HTMLComponent(tags map[string]string) h.HTMLComponent

func (*Setting) Scan

func (setting *Setting) Scan(value interface{}) error

Scan scan value from database into struct

func (Setting) Value

func (setting Setting) Value() (driver.Value, error)

Value get value from struct, and save into database

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)

type Variables

type Variables map[string]string

func (*Variables) Scan

func (setting *Variables) Scan(value interface{}) error

Scan scan value from database into struct

func (Variables) Value

func (setting Variables) Value() (driver.Value, error)

Value get value from struct, and save into database

Jump to

Keyboard shortcuts

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