update PermaLink

This commit is contained in:
aichy126 2022-12-13 16:55:23 +08:00
parent 99427afa30
commit 98385afe4c
6 changed files with 61 additions and 41 deletions

View File

@ -6475,7 +6475,6 @@ const docTemplate = `{
"required": [ "required": [
"contact_email", "contact_email",
"name", "name",
"permalink",
"site_url" "site_url"
], ],
"properties": { "properties": {
@ -6491,11 +6490,6 @@ const docTemplate = `{
"type": "string", "type": "string",
"maxLength": 128 "maxLength": 128
}, },
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"short_description": { "short_description": {
"type": "string", "type": "string",
"maxLength": 255 "maxLength": 255
@ -6511,7 +6505,6 @@ const docTemplate = `{
"required": [ "required": [
"contact_email", "contact_email",
"name", "name",
"permalink",
"site_url" "site_url"
], ],
"properties": { "properties": {
@ -6527,11 +6520,6 @@ const docTemplate = `{
"type": "string", "type": "string",
"maxLength": 128 "maxLength": 128
}, },
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"short_description": { "short_description": {
"type": "string", "type": "string",
"maxLength": 255 "maxLength": 255
@ -6623,9 +6611,15 @@ const docTemplate = `{
"schema.SiteSeoReq": { "schema.SiteSeoReq": {
"type": "object", "type": "object",
"required": [ "required": [
"permalink",
"robots" "robots"
], ],
"properties": { "properties": {
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"robots": { "robots": {
"type": "string" "type": "string"
} }
@ -6634,9 +6628,15 @@ const docTemplate = `{
"schema.SiteSeoResp": { "schema.SiteSeoResp": {
"type": "object", "type": "object",
"required": [ "required": [
"permalink",
"robots" "robots"
], ],
"properties": { "properties": {
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"robots": { "robots": {
"type": "string" "type": "string"
} }

View File

@ -6463,7 +6463,6 @@
"required": [ "required": [
"contact_email", "contact_email",
"name", "name",
"permalink",
"site_url" "site_url"
], ],
"properties": { "properties": {
@ -6479,11 +6478,6 @@
"type": "string", "type": "string",
"maxLength": 128 "maxLength": 128
}, },
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"short_description": { "short_description": {
"type": "string", "type": "string",
"maxLength": 255 "maxLength": 255
@ -6499,7 +6493,6 @@
"required": [ "required": [
"contact_email", "contact_email",
"name", "name",
"permalink",
"site_url" "site_url"
], ],
"properties": { "properties": {
@ -6515,11 +6508,6 @@
"type": "string", "type": "string",
"maxLength": 128 "maxLength": 128
}, },
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"short_description": { "short_description": {
"type": "string", "type": "string",
"maxLength": 255 "maxLength": 255
@ -6611,9 +6599,15 @@
"schema.SiteSeoReq": { "schema.SiteSeoReq": {
"type": "object", "type": "object",
"required": [ "required": [
"permalink",
"robots" "robots"
], ],
"properties": { "properties": {
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"robots": { "robots": {
"type": "string" "type": "string"
} }
@ -6622,9 +6616,15 @@
"schema.SiteSeoResp": { "schema.SiteSeoResp": {
"type": "object", "type": "object",
"required": [ "required": [
"permalink",
"robots" "robots"
], ],
"properties": { "properties": {
"permalink": {
"type": "integer",
"maximum": 3,
"minimum": 0
},
"robots": { "robots": {
"type": "string" "type": "string"
} }

View File

@ -1200,10 +1200,6 @@ definitions:
name: name:
maxLength: 128 maxLength: 128
type: string type: string
permalink:
maximum: 3
minimum: 0
type: integer
short_description: short_description:
maxLength: 255 maxLength: 255
type: string type: string
@ -1213,7 +1209,6 @@ definitions:
required: required:
- contact_email - contact_email
- name - name
- permalink
- site_url - site_url
type: object type: object
schema.SiteGeneralResp: schema.SiteGeneralResp:
@ -1227,10 +1222,6 @@ definitions:
name: name:
maxLength: 128 maxLength: 128
type: string type: string
permalink:
maximum: 3
minimum: 0
type: integer
short_description: short_description:
maxLength: 255 maxLength: 255
type: string type: string
@ -1240,7 +1231,6 @@ definitions:
required: required:
- contact_email - contact_email
- name - name
- permalink
- site_url - site_url
type: object type: object
schema.SiteInterfaceReq: schema.SiteInterfaceReq:
@ -1299,16 +1289,26 @@ definitions:
type: object type: object
schema.SiteSeoReq: schema.SiteSeoReq:
properties: properties:
permalink:
maximum: 3
minimum: 0
type: integer
robots: robots:
type: string type: string
required: required:
- permalink
- robots - robots
type: object type: object
schema.SiteSeoResp: schema.SiteSeoResp:
properties: properties:
permalink:
maximum: 3
minimum: 0
type: integer
robots: robots:
type: string type: string
required: required:
- permalink
- robots - robots
type: object type: object
schema.SiteWriteReq: schema.SiteWriteReq:

View File

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

View File

@ -15,11 +15,11 @@ type SiteGeneralReq struct {
Description string `validate:"omitempty,gt=3,lte=2000" form:"description" json:"description"` 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"` 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"` 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 { 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() { func (r *SiteGeneralReq) FormatSiteUrl() {
@ -109,6 +109,7 @@ type TemplateSiteInfoResp struct {
General *SiteGeneralResp `json:"general"` General *SiteGeneralResp `json:"general"`
Interface *SiteInterfaceResp `json:"interface"` Interface *SiteInterfaceResp `json:"interface"`
Branding *SiteBrandingResp `json:"branding"` Branding *SiteBrandingResp `json:"branding"`
SiteSeo *SiteSeoReq `json:"siteseo"`
Title string Title string
Year string Year string
Canonical string Canonical string

View File

@ -87,3 +87,16 @@ func (s *SiteInfoCommonService) GetSiteLegal(ctx context.Context) (resp *schema.
_ = json.Unmarshal([]byte(siteInfo.Content), resp) _ = json.Unmarshal([]byte(siteInfo.Content), resp)
return resp, nil return resp, nil
} }
func (s *SiteInfoCommonService) GetSiteSeo(ctx context.Context) (resp *schema.SiteSeoReq, err error) {
resp = &schema.SiteSeoReq{}
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeSeo)
if err != nil {
return nil, err
}
if !exist {
return resp, nil
}
_ = json.Unmarshal([]byte(siteInfo.Content), resp)
return resp, nil
}