获取SEO @param page 页面 @param defaultTitle 默认标题 @param defaultKeywords 默认关键字 @param defaultDescription 默认摘要 @param Sitename 站点名称 @return seo SEO数据
(page string, defaultTitle, defaultKeywords, defaultDescription, Sitename string)
| 65 | //@param Sitename 站点名称 |
| 66 | //@return seo SEO数据 |
| 67 | func (this *Seo) GetByPage(page string, defaultTitle, defaultKeywords, defaultDescription, Sitename string) (seo map[string]string) { |
| 68 | var seoStruct Seo |
| 69 | seo = make(map[string]string) |
| 70 | defSeo := map[string]string{ |
| 71 | "Title": defaultTitle, |
| 72 | "Keywords": defaultKeywords, |
| 73 | "Description": defaultDescription, |
| 74 | "Sitename": Sitename, |
| 75 | } |
| 76 | replace := map[string]string{ |
| 77 | "Title": "{title}", |
| 78 | "Keywords": "{keywords}", |
| 79 | "Description": "{description}", |
| 80 | "Sitename": "{sitename}", |
| 81 | } |
| 82 | replaceFunc := func(item string, defSeo map[string]string) string { |
| 83 | for k, v := range replace { |
| 84 | item = strings.Replace(item, v, defSeo[k], -1) |
| 85 | } |
| 86 | return item |
| 87 | } |
| 88 | orm.NewOrm().QueryTable(GetTableSeo()).Filter("Page", page).One(&seoStruct) |
| 89 | if seoStruct.Id > 0 { |
| 90 | seo["Title"] = replaceFunc(seoStruct.Title, defSeo) |
| 91 | seo["Keywords"] = replaceFunc(seoStruct.Keywords, defSeo) |
| 92 | seo["Description"] = replaceFunc(seoStruct.Description, defSeo) |
| 93 | } |
| 94 | return seo |
| 95 | } |
| 96 | |
| 97 | //baseUrl := this.Ctx.Input.Scheme() + "://" + this.Ctx.Request.Host |
| 98 | //if host := beego.AppConfig.String("sitemap_host"); len(host) > 0 { |