Skip to content

Commit d3a29e7

Browse files
committed
feat(theme): add layout options for site theme configuration
1 parent c2a6280 commit d3a29e7

File tree

6 files changed

+15
-2
lines changed

6 files changed

+15
-2
lines changed

internal/base/constant/site_info.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ const (
4343
ColorSchemeLight = "light"
4444
ColorSchemeDark = "dark"
4545
ColorSchemeSystem = "system"
46+
47+
ThemeLayoutFullWidth = "Full-width"
48+
ThemeLayoutFixedWidth = "Fixed-width"
4649
)
4750

4851
const (

internal/migrations/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (m *Mentor) initSiteInfoLegalConfig() {
236236
}
237237

238238
func (m *Mentor) initSiteInfoThemeConfig() {
239-
themeConfig := `{"theme":"default","theme_config":{"default":{"navbar_style":"#0033ff","primary_color":"#0033ff"}}}`
239+
themeConfig := fmt.Sprintf(`{"theme":"default","theme_config":{"default":{"navbar_style":"#0033ff","primary_color":"#0033ff"}},"layout":"%s"}`, constant.ThemeLayoutFullWidth)
240240
_, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{
241241
Type: "theme",
242242
Content: themeConfig,

internal/migrations/v5.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"encoding/json"
2525
"fmt"
2626

27+
"github.com/apache/answer/internal/base/constant"
2728
"github.com/apache/answer/internal/entity"
2829
"xorm.io/xorm"
2930
)
@@ -50,7 +51,7 @@ func addThemeAndPrivateMode(ctx context.Context, x *xorm.Engine) error {
5051
}
5152
}
5253

53-
themeConfig := `{"theme":"default","theme_config":{"default":{"navbar_style":"#0033ff","primary_color":"#0033ff"}}}`
54+
themeConfig := fmt.Sprintf(`{"theme":"default","theme_config":{"default":{"navbar_style":"#0033ff","primary_color":"#0033ff"}},"layout":"%s"}`, constant.ThemeLayoutFullWidth)
5455
themeSiteInfo := &entity.SiteInfo{
5556
Type: "theme",
5657
Content: themeConfig,

internal/schema/siteinfo_schema.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ type SiteThemeReq struct {
181181
Theme string `validate:"required,gt=0,lte=255" json:"theme"`
182182
ThemeConfig map[string]any `validate:"omitempty" json:"theme_config"`
183183
ColorScheme string `validate:"omitempty,gt=0,lte=100" json:"color_scheme"`
184+
Layout string `validate:"omitempty,oneof=Full-width Fixed-width" json:"layout"`
184185
}
185186

186187
type SiteSeoReq struct {
@@ -217,6 +218,7 @@ type SiteThemeResp struct {
217218
Theme string `json:"theme"`
218219
ThemeConfig map[string]any `json:"theme_config"`
219220
ColorScheme string `json:"color_scheme"`
221+
Layout string `json:"layout"`
220222
}
221223

222224
func (s *SiteThemeResp) TrTheme(ctx context.Context) {

internal/service/siteinfo/siteinfo_service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ func (s *SiteInfoService) SaveSiteCustomCssHTML(ctx context.Context, req *schema
252252

253253
// SaveSiteTheme save site custom html configuration
254254
func (s *SiteInfoService) SaveSiteTheme(ctx context.Context, req *schema.SiteThemeReq) (err error) {
255+
if len(req.Layout) == 0 {
256+
req.Layout = constant.ThemeLayoutFullWidth
257+
}
255258
content, _ := json.Marshal(req)
256259
data := &entity.SiteInfo{
257260
Type: constant.SiteTypeTheme,

internal/service/siteinfo_common/siteinfo_service.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,14 @@ func (s *siteInfoCommonService) GetSiteCustomCssHTML(ctx context.Context) (resp
198198
func (s *siteInfoCommonService) GetSiteTheme(ctx context.Context) (resp *schema.SiteThemeResp, err error) {
199199
resp = &schema.SiteThemeResp{
200200
ThemeOptions: schema.GetThemeOptions,
201+
Layout: constant.ThemeLayoutFullWidth,
201202
}
202203
if err = s.GetSiteInfoByType(ctx, constant.SiteTypeTheme, resp); err != nil {
203204
return nil, err
204205
}
206+
if resp.Layout == "" {
207+
resp.Layout = constant.ThemeLayoutFullWidth
208+
}
205209
resp.TrTheme(ctx)
206210
return resp, nil
207211
}

0 commit comments

Comments
 (0)