seo

package module
v0.0.0-...-8f5a22f Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2020 License: MIT Imports: 20 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. Using the QOR Admin interface, an administrator can easily manage the content of an HTML page's title, description, and meta tags.

GoDoc

Definition

// The `QorSeoSetting` struct is a normal GORM-backend model, need to run migration before using it
db.AutoMigrate(&seo.QorSeoSetting{})

// SeoGlobalSetting used to generate `Site-wide Settings` part
type SeoGlobalSetting struct {
    SiteName string
}

SeoCollection = seo.New()

// Configure `Site-wide Settings`
SeoCollection.RegisterGlobalVaribles(&SeoGlobalSetting{SiteName: "ASICS"})

// Configure SEO storage model, you could customize it by embed seo.QorSeoSetting to your custom model
SeoCollection.SettingResource = Admin.AddResource(&seo.QorSeoSetting{}, &admin.Config{Name: "SEO", Invisible: true})

// Configure `Page Metadata Defaults`
SeoCollection.RegisterSeo(&seo.SEO{
    Name:     "Default Page",
})

SeoCollection.RegisterSeo(&seo.SEO{
    Name:     "Category Page",
    // Defined what Varibles could be using in title, description and keywords
    Varibles: []string{"CategoryName"},
    // Generated a mapping to replace the Variable, e.g. title: 'Qor - {{CategoryName}}', will be dislayed as 'Qor - Clothing'
    Context: func(objects ...interface{}) map[string]string {
        values := make(map[string]string)
        if len(objects) > 0 {
            category := objects[0].(Category)
            values["CategoryName"] = category.Name
        }
        return values
    },
})

Usage

qorContext := &qor.Context{DB: db}

// render default meta tags
SeoCollection.Render(qorContext, "Default Page")

// render cateogry pages' meta tags
var category Category
db.First(&category, "code = ?", "clothing")
SeoCollection.Render(qorContext, "Category Page", category)

Structured Data

// micro search
seo.MicroSearch{
  URL:    "http://demo.getqor.com",
  Target: "http://demo.getqor.com/search?q=",
}.Render()

// micro contact
seo.MicroContact{
  URL:         "http://demo.getqor.com",
  Telephone:   "080-0012-3232",
  ContactType: "Customer Service",
}.Render()

// micro product
seo.MicroProduct{
  Name: "Kenmore White 17 Microwave",
  Image: "http://getqor.com/source/images/qor-logo.png",
  Description: "0.7 cubic feet countertop microwave. Has six preset cooking categories and convenience features like Add-A-Minute and Child Lock."
  BrandName: "ThePlant",
  SKU: "L1212",
  PriceCurrency: "USD",
  Price: 100,
  SellerName: "ThePlant",
}.Render()

License

Released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MicroProductTemplate = `` /* 992-byte string literal not displayed */

	MicroContactTemplate = `` /* 273-byte string literal not displayed */

	MicroSearchTemplate = `` /* 262-byte string literal not displayed */

)

MicroProductTemplate a bundle of microdata templates

Functions

This section is empty.

Types

type Collection

type Collection struct {
	Name            string
	SettingResource *admin.Resource
	// contains filtered or unexported fields
}

Collection will hold registered seo configures and global setting definition and other configures

func New

func New(name string) *Collection

New initialize a SeoCollection instance

func (*Collection) ConfigureQorResource

func (collection *Collection) ConfigureQorResource(res resource.Resourcer)

ConfigureQorResource configure seoCollection for qor admin

func (*Collection) GetSEO

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

GetSEO get a Seo by name

func (Collection) GetSEOSetting

func (collection Collection) GetSEOSetting(context *qor.Context, name string, objects ...interface{}) Setting

GetSEOSetting return SEO title, keywords and description and open graph settings

func (*Collection) RegisterGlobalVaribles

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

RegisterGlobalVaribles register global setting struct and will represents as 'Site-wide Settings' part in admin

func (*Collection) RegisterSEO

func (collection *Collection) RegisterSEO(seo *SEO)

RegisterSEO register a seo

func (Collection) Render

func (collection Collection) Render(context *qor.Context, name string, objects ...interface{}) template.HTML

Render render SEO Setting

func (*Collection) SEOSettingURL

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

SEOSettingURL get setting inline edit url by name

type MicroContact

type MicroContact struct {
	URL         string
	Telephone   string
	ContactType string
}

MicroContact micro search definition, ref: https://developers.google.com/structured-data/customize/contact-points

func (MicroContact) Render

func (contact MicroContact) Render() template.HTML

Render render micro contact structured data

type MicroProduct

type MicroProduct struct {
	Name            string
	Image           string
	Description     string
	BrandName       string
	SKU             string
	RatingValue     float32
	ReviewCount     int
	PriceCurrency   string
	Price           float64
	PriceValidUntil string
	SellerName      string
}

MicroProduct micro product definition, ref: https://developers.google.com/structured-data/rich-snippets/products

func (MicroProduct) Render

func (product MicroProduct) Render() template.HTML

Render render micro product structured data

type MicroSearch

type MicroSearch struct {
	URL        string
	Target     string
	QueryInput string
}

MicroSearch micro search definition, ref: https://developers.google.com/structured-data/slsb-overview e.g.

Target: https://query.example-petstore.com/search?q={keyword}

func (MicroSearch) FormattedQueryInput

func (search MicroSearch) FormattedQueryInput() string

FormattedQueryInput format query input

func (MicroSearch) Render

func (search MicroSearch) Render() template.HTML

Render render micro search structured data

type OpenGraphConfig

type OpenGraphConfig struct {
	ImageResource *admin.Resource
	Size          *media.Size
}

OpenGraphConfig open graph config

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
	IsGlobalSEO bool

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time `gorm:"index"`
	// contains filtered or unexported fields
}

QorSEOSetting default seo model

func (QorSEOSetting) GetDescription

func (s QorSEOSetting) GetDescription() string

GetDescription get Setting's description

func (QorSEOSetting) GetGlobalSetting

func (s QorSEOSetting) GetGlobalSetting() map[string]string

GetGlobalSetting get QorSeoSetting's globalSetting

func (QorSEOSetting) GetIsGlobalSEO

func (s QorSEOSetting) GetIsGlobalSEO() bool

GetIsGlobalSEO get QorSEOSetting's isGlobal

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) GetOpenGraphDescription

func (s QorSEOSetting) GetOpenGraphDescription() string

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) GetOpenGraphTitle

func (s QorSEOSetting) GetOpenGraphTitle() string

func (QorSEOSetting) GetOpenGraphType

func (s QorSEOSetting) GetOpenGraphType() string

func (QorSEOSetting) GetOpenGraphURL

func (s QorSEOSetting) GetOpenGraphURL() string

func (QorSEOSetting) GetSEO

func (s QorSEOSetting) GetSEO() *SEO

GetSEO get Setting's SEO configure

func (QorSEOSetting) GetSEOSetting

func (s QorSEOSetting) GetSEOSetting() Setting

GetSEOSetting get seo setting

func (QorSEOSetting) GetSEOType

func (s QorSEOSetting) GetSEOType() string

GetSEOType get QorSeoSetting's type

func (QorSEOSetting) GetTitle

func (s QorSEOSetting) GetTitle() string

GetTitle get Setting's title

func (*QorSEOSetting) SetCollection

func (s *QorSEOSetting) SetCollection(collection *Collection)

SetCollection set Setting's collection

func (*QorSEOSetting) SetGlobalSetting

func (s *QorSEOSetting) SetGlobalSetting(globalSetting map[string]string)

SetGlobalSetting set QorSeoSetting's globalSetting

func (*QorSEOSetting) SetIsGlobalSEO

func (s *QorSEOSetting) SetIsGlobalSEO(isGlobal bool)

SetIsGlobalSEO set QorSeoSetting's isGlobal

func (*QorSEOSetting) SetName

func (s *QorSEOSetting) SetName(name string)

SetName set QorSeoSetting's name

func (*QorSEOSetting) SetSEOType

func (s *QorSEOSetting) SetSEOType(t string)

SetSEOType set QorSeoSetting's type

type QorSEOSettingInterface

type QorSEOSettingInterface interface {
	GetName() string
	SetName(string)
	GetSEOSetting() Setting
	GetGlobalSetting() map[string]string
	SetGlobalSetting(map[string]string)
	GetSEOType() string
	SetSEOType(string)
	GetIsGlobalSEO() bool
	SetIsGlobalSEO(bool)
	GetTitle() string
	GetDescription() string
	GetKeywords() string
	SetCollection(*Collection)
	GetOpenGraphTitle() string
	GetOpenGraphDescription() string
	GetOpenGraphURL() string
	GetOpenGraphType() string
	GetOpenGraphImageURL() string
	GetOpenGraphImageFromMediaLibrary() media_library.MediaBox
	GetOpenGraphMetadata() []OpenGraphMetadata
}

QorSEOSettingInterface support customize Seo model

type SEO

type SEO struct {
	Name      string
	Varibles  []string
	OpenGraph *OpenGraphConfig
	Context   func(...interface{}) map[string]string
	// contains filtered or unexported fields
}

SEO represents a seo object for a page

type Setting

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

Setting defined meta's attributes

func (Setting) ConfigureQorMetaBeforeInitialize

func (setting Setting) ConfigureQorMetaBeforeInitialize(meta resource.Metaor)

ConfigureQorMetaBeforeInitialize configure SEO setting for qor admin

func (Setting) ConfigureQorResource

func (setting Setting) ConfigureQorResource(res resource.Resourcer)

ConfigureQorResource configure resource for seo setting

func (Setting) FormattedHTML

func (setting Setting) FormattedHTML(context *qor.Context) template.HTML

FormattedHTML return formated seo setting as HTML

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

Jump to

Keyboard shortcuts

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