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

View File

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

View File

@ -1200,10 +1200,6 @@ definitions:
name:
maxLength: 128
type: string
permalink:
maximum: 3
minimum: 0
type: integer
short_description:
maxLength: 255
type: string
@ -1213,7 +1209,6 @@ definitions:
required:
- contact_email
- name
- permalink
- site_url
type: object
schema.SiteGeneralResp:
@ -1227,10 +1222,6 @@ definitions:
name:
maxLength: 128
type: string
permalink:
maximum: 3
minimum: 0
type: integer
short_description:
maxLength: 255
type: string
@ -1240,7 +1231,6 @@ definitions:
required:
- contact_email
- name
- permalink
- site_url
type: object
schema.SiteInterfaceReq:
@ -1299,16 +1289,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.SiteWriteReq:

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

@ -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() {
@ -109,6 +109,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

View File

@ -87,3 +87,16 @@ func (s *SiteInfoCommonService) GetSiteLegal(ctx context.Context) (resp *schema.
_ = json.Unmarshal([]byte(siteInfo.Content), resp)
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
}