Merge remote-tracking branch 'origin/feat/0.6.0/seo' into feat/0.7.0/user-manage

# Conflicts:
#	internal/service/siteinfo_common/siteinfo_service.go
This commit is contained in:
LinkinStar 2022-12-13 17:07:32 +08:00
commit 7450c4cad7
7 changed files with 51 additions and 43 deletions

View File

@ -6871,7 +6871,6 @@ const docTemplate = `{
"required": [
"contact_email",
"name",
"permalink",
"site_url"
],
"properties": {
@ -6887,11 +6886,6 @@ const docTemplate = `{
"type": "string",
"maxLength": 128
},
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"short_description": {
"type": "string",
"maxLength": 255
@ -6907,7 +6901,6 @@ const docTemplate = `{
"required": [
"contact_email",
"name",
"permalink",
"site_url"
],
"properties": {
@ -6923,11 +6916,6 @@ const docTemplate = `{
"type": "string",
"maxLength": 128
},
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"short_description": {
"type": "string",
"maxLength": 255
@ -7064,9 +7052,15 @@ const docTemplate = `{
"schema.SiteSeoReq": {
"type": "object",
"required": [
"permalink",
"robots"
],
"properties": {
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"robots": {
"type": "string"
}
@ -7075,9 +7069,15 @@ const docTemplate = `{
"schema.SiteSeoResp": {
"type": "object",
"required": [
"permalink",
"robots"
],
"properties": {
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"robots": {
"type": "string"
}

View File

@ -6859,7 +6859,6 @@
"required": [
"contact_email",
"name",
"permalink",
"site_url"
],
"properties": {
@ -6875,11 +6874,6 @@
"type": "string",
"maxLength": 128
},
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"short_description": {
"type": "string",
"maxLength": 255
@ -6895,7 +6889,6 @@
"required": [
"contact_email",
"name",
"permalink",
"site_url"
],
"properties": {
@ -6911,11 +6904,6 @@
"type": "string",
"maxLength": 128
},
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"short_description": {
"type": "string",
"maxLength": 255
@ -7052,9 +7040,15 @@
"schema.SiteSeoReq": {
"type": "object",
"required": [
"permalink",
"robots"
],
"properties": {
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"robots": {
"type": "string"
}
@ -7063,9 +7057,15 @@
"schema.SiteSeoResp": {
"type": "object",
"required": [
"permalink",
"robots"
],
"properties": {
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"robots": {
"type": "string"
}

View File

@ -1247,10 +1247,6 @@ definitions:
name:
maxLength: 128
type: string
permalink:
maximum: 3
minimum: 0
type: integer
short_description:
maxLength: 255
type: string
@ -1260,7 +1256,6 @@ definitions:
required:
- contact_email
- name
- permalink
- site_url
type: object
schema.SiteGeneralResp:
@ -1274,10 +1269,6 @@ definitions:
name:
maxLength: 128
type: string
permalink:
maximum: 3
minimum: 0
type: integer
short_description:
maxLength: 255
type: string
@ -1287,7 +1278,6 @@ definitions:
required:
- contact_email
- name
- permalink
- site_url
type: object
schema.SiteInfoResp:
@ -1375,16 +1365,26 @@ definitions:
type: object
schema.SiteSeoReq:
properties:
permalink:
maximum: 3
minimum: 0
type: integer
robots:
type: string
required:
- permalink
- robots
type: object
schema.SiteSeoResp:
properties:
permalink:
maximum: 3
minimum: 0
type: integer
robots:
type: string
required:
- permalink
- robots
type: object
schema.SiteThemeReq:

View File

@ -29,6 +29,7 @@ func NewScheduledTaskManager(
func (s *ScheduledTaskManager) Run() {
fmt.Println("start cron")
s.questionService.SitemapCron(context.Background())
c := cron.New()
c.AddFunc("0 */1 * * *", func() {
ctx := context.Background()

View File

@ -75,6 +75,12 @@ func (tc *TemplateController) SiteInfo(ctx *gin.Context) *schema.TemplateSiteInf
if err != nil {
log.Error(err)
}
resp.SiteSeo, err = tc.siteInfoService.GetSiteSeo(ctx)
if err != nil {
log.Error(err)
}
resp.Year = fmt.Sprintf("%d", time.Now().Year())
return resp
}
@ -101,7 +107,7 @@ func (tc *TemplateController) Index(ctx *gin.Context) {
siteInfo.Canonical = fmt.Sprintf("%s", siteInfo.General.SiteUrl)
UrlUseTitle := false
if siteInfo.General.PermaLink == schema.PermaLinkQuestionIDAndTitle {
if siteInfo.SiteSeo.PermaLink == schema.PermaLinkQuestionIDAndTitle {
UrlUseTitle = true
}
siteInfo.Title = ""
@ -130,7 +136,7 @@ func (tc *TemplateController) QuestionList(ctx *gin.Context) {
siteInfo.Canonical = fmt.Sprintf("%s/questions", siteInfo.General.SiteUrl)
UrlUseTitle := false
if siteInfo.General.PermaLink == schema.PermaLinkQuestionIDAndTitle {
if siteInfo.SiteSeo.PermaLink == schema.PermaLinkQuestionIDAndTitle {
UrlUseTitle = true
}
siteInfo.Title = fmt.Sprintf("Questions - %s", siteInfo.General.Name)
@ -154,7 +160,7 @@ func (tc *TemplateController) QuestionInfo301Jump(ctx *gin.Context, siteInfo *sc
}
url = fmt.Sprintf("%s/questions/%s", siteInfo.General.SiteUrl, id)
if siteInfo.General.PermaLink == schema.PermaLinkQuestionID {
if siteInfo.SiteSeo.PermaLink == schema.PermaLinkQuestionID {
//not have title
if titleIsAnswerID || len(title) == 0 {
return false, ""
@ -219,7 +225,7 @@ func (tc *TemplateController) QuestionInfo(ctx *gin.Context) {
}
encodeTitle := htmltext.UrlTitle(detail.Title)
siteInfo.Canonical = fmt.Sprintf("%s/questions/%s/%s", siteInfo.General.SiteUrl, id, encodeTitle)
if siteInfo.General.PermaLink == schema.PermaLinkQuestionID {
if siteInfo.SiteSeo.PermaLink == schema.PermaLinkQuestionID {
siteInfo.Canonical = fmt.Sprintf("%s/questions/%s", siteInfo.General.SiteUrl, id)
}
jsonLD := &schema.QAPageJsonLD{}
@ -326,7 +332,7 @@ func (tc *TemplateController) TagInfo(ctx *gin.Context) {
siteInfo.Keywords = taginifo.DisplayName
UrlUseTitle := false
if siteInfo.General.PermaLink == schema.PermaLinkQuestionIDAndTitle {
if siteInfo.SiteSeo.PermaLink == schema.PermaLinkQuestionIDAndTitle {
UrlUseTitle = true
}
siteInfo.Title = fmt.Sprintf("'%s' Questions - %s", taginifo.DisplayName, siteInfo.General.Name)

View File

@ -72,8 +72,8 @@ func (t *TemplateRenderController) SitemapPage(ctx *gin.Context, page int) error
cachekey := fmt.Sprintf(schema.SitemapPageCachekey, page)
infoStr, err := t.data.Cache.GetString(ctx, cachekey)
if err != nil {
log.Errorf("get Cache failed: %s", err)
return err
//If there is no cache, return directly.
return nil
}
if err = json.Unmarshal([]byte(infoStr), sitemapInfo); err != nil {
log.Errorf("get sitemap info failed: %s", err)

View File

@ -15,11 +15,11 @@ type SiteGeneralReq struct {
Description string `validate:"omitempty,gt=3,lte=2000" form:"description" json:"description"`
SiteUrl string `validate:"required,gt=1,lte=512,url" form:"site_url" json:"site_url"`
ContactEmail string `validate:"required,gt=1,lte=512,email" form:"contact_email" json:"contact_email"`
PermaLink int `validate:"required,lte=3,gte=0" form:"permalink" json:"permalink"`
}
type SiteSeoReq struct {
Robots string `validate:"required" form:"robots" json:"robots"`
PermaLink int `validate:"required,lte=3,gte=0" form:"permalink" json:"permalink"`
Robots string `validate:"required" form:"robots" json:"robots"`
}
func (r *SiteGeneralReq) FormatSiteUrl() {
@ -142,6 +142,7 @@ type TemplateSiteInfoResp struct {
General *SiteGeneralResp `json:"general"`
Interface *SiteInterfaceResp `json:"interface"`
Branding *SiteBrandingResp `json:"branding"`
SiteSeo *SiteSeoReq `json:"siteseo"`
Title string
Year string
Canonical string