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.
Definition
db.AutoMigrate(&seo.QorSeoSetting{})
type SeoGlobalSetting struct {
SiteName string
}
SeoCollection = seo.New()
SeoCollection.RegisterGlobalVaribles(&SeoGlobalSetting{SiteName: "ASICS"})
SeoCollection.SettingResource = Admin.AddResource(&seo.QorSeoSetting{}, &admin.Config{Name: "SEO", Invisible: true})
SeoCollection.RegisterSeo(&seo.SEO{
Name: "Default Page",
})
SeoCollection.RegisterSeo(&seo.SEO{
Name: "Category Page",
Varibles: []string{"CategoryName"},
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}
SeoCollection.Render(qorContext, "Default Page")
var category Category
db.First(&category, "code = ?", "clothing")
SeoCollection.Render(qorContext, "Category Page", category)
Structured Data
seo.MicroSearch{
URL: "http://demo.getqor.com",
Target: "http://demo.getqor.com/search?q=",
}.Render()
seo.MicroContact{
URL: "http://demo.getqor.com",
Telephone: "080-0012-3232",
ContactType: "Customer Service",
}.Render()
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()
To use multiple seo setting in one object
Add a field called CurrentSeoField
in the struct, it must be put in front of seo settings.
type Obj struct {
CurrentSeoField string `gorm:"-"`
JapaneseSeo qor_seo.Setting
EnglishSeo qor_seo.Setting
}
Then when rendering seo, set the name of seo setting you want to render. E.g. EnglishSeo
obj.CurrentSeoField = "EnglishSeo"
Then the proper seo setting will be used in this rendering. If has CurrentSeoField
set but with no value or cannot find seo setting by given name. the first seo setting will be used as default.
License
Released under the MIT License.