This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch feat/1.7.2/layout
in repository https://gitbox.apache.org/repos/asf/answer.git

commit d3a29e7ad9dbb2454ea315602eabc58c48486113
Author: LinkinStars <[email protected]>
AuthorDate: Fri Dec 19 12:23:41 2025 +0800

    feat(theme): add layout options for site theme configuration
---
 internal/base/constant/site_info.go                  | 3 +++
 internal/migrations/init.go                          | 2 +-
 internal/migrations/v5.go                            | 3 ++-
 internal/schema/siteinfo_schema.go                   | 2 ++
 internal/service/siteinfo/siteinfo_service.go        | 3 +++
 internal/service/siteinfo_common/siteinfo_service.go | 4 ++++
 6 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/internal/base/constant/site_info.go 
b/internal/base/constant/site_info.go
index 2d666834..81481bab 100644
--- a/internal/base/constant/site_info.go
+++ b/internal/base/constant/site_info.go
@@ -43,6 +43,9 @@ const (
        ColorSchemeLight   = "light"
        ColorSchemeDark    = "dark"
        ColorSchemeSystem  = "system"
+
+       ThemeLayoutFullWidth  = "Full-width"
+       ThemeLayoutFixedWidth = "Fixed-width"
 )
 
 const (
diff --git a/internal/migrations/init.go b/internal/migrations/init.go
index 8a72794f..5ffb3771 100644
--- a/internal/migrations/init.go
+++ b/internal/migrations/init.go
@@ -236,7 +236,7 @@ func (m *Mentor) initSiteInfoLegalConfig() {
 }
 
 func (m *Mentor) initSiteInfoThemeConfig() {
-       themeConfig := 
`{"theme":"default","theme_config":{"default":{"navbar_style":"#0033ff","primary_color":"#0033ff"}}}`
+       themeConfig := 
fmt.Sprintf(`{"theme":"default","theme_config":{"default":{"navbar_style":"#0033ff","primary_color":"#0033ff"}},"layout":"%s"}`,
 constant.ThemeLayoutFullWidth)
        _, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{
                Type:    "theme",
                Content: themeConfig,
diff --git a/internal/migrations/v5.go b/internal/migrations/v5.go
index 91d12f15..b988dc65 100644
--- a/internal/migrations/v5.go
+++ b/internal/migrations/v5.go
@@ -24,6 +24,7 @@ import (
        "encoding/json"
        "fmt"
 
+       "github.com/apache/answer/internal/base/constant"
        "github.com/apache/answer/internal/entity"
        "xorm.io/xorm"
 )
@@ -50,7 +51,7 @@ func addThemeAndPrivateMode(ctx context.Context, x 
*xorm.Engine) error {
                }
        }
 
-       themeConfig := 
`{"theme":"default","theme_config":{"default":{"navbar_style":"#0033ff","primary_color":"#0033ff"}}}`
+       themeConfig := 
fmt.Sprintf(`{"theme":"default","theme_config":{"default":{"navbar_style":"#0033ff","primary_color":"#0033ff"}},"layout":"%s"}`,
 constant.ThemeLayoutFullWidth)
        themeSiteInfo := &entity.SiteInfo{
                Type:    "theme",
                Content: themeConfig,
diff --git a/internal/schema/siteinfo_schema.go 
b/internal/schema/siteinfo_schema.go
index 7ab65751..9eb919a0 100644
--- a/internal/schema/siteinfo_schema.go
+++ b/internal/schema/siteinfo_schema.go
@@ -181,6 +181,7 @@ type SiteThemeReq struct {
        Theme       string         `validate:"required,gt=0,lte=255" 
json:"theme"`
        ThemeConfig map[string]any `validate:"omitempty" json:"theme_config"`
        ColorScheme string         `validate:"omitempty,gt=0,lte=100" 
json:"color_scheme"`
+       Layout      string         `validate:"omitempty,oneof=Full-width 
Fixed-width" json:"layout"`
 }
 
 type SiteSeoReq struct {
@@ -217,6 +218,7 @@ type SiteThemeResp struct {
        Theme        string         `json:"theme"`
        ThemeConfig  map[string]any `json:"theme_config"`
        ColorScheme  string         `json:"color_scheme"`
+       Layout       string         `json:"layout"`
 }
 
 func (s *SiteThemeResp) TrTheme(ctx context.Context) {
diff --git a/internal/service/siteinfo/siteinfo_service.go 
b/internal/service/siteinfo/siteinfo_service.go
index f355d09f..1eb18706 100644
--- a/internal/service/siteinfo/siteinfo_service.go
+++ b/internal/service/siteinfo/siteinfo_service.go
@@ -252,6 +252,9 @@ func (s *SiteInfoService) SaveSiteCustomCssHTML(ctx 
context.Context, req *schema
 
 // SaveSiteTheme save site custom html configuration
 func (s *SiteInfoService) SaveSiteTheme(ctx context.Context, req 
*schema.SiteThemeReq) (err error) {
+       if len(req.Layout) == 0 {
+               req.Layout = constant.ThemeLayoutFullWidth
+       }
        content, _ := json.Marshal(req)
        data := &entity.SiteInfo{
                Type:    constant.SiteTypeTheme,
diff --git a/internal/service/siteinfo_common/siteinfo_service.go 
b/internal/service/siteinfo_common/siteinfo_service.go
index fda11722..8a4b1366 100644
--- a/internal/service/siteinfo_common/siteinfo_service.go
+++ b/internal/service/siteinfo_common/siteinfo_service.go
@@ -198,10 +198,14 @@ func (s *siteInfoCommonService) GetSiteCustomCssHTML(ctx 
context.Context) (resp
 func (s *siteInfoCommonService) GetSiteTheme(ctx context.Context) (resp 
*schema.SiteThemeResp, err error) {
        resp = &schema.SiteThemeResp{
                ThemeOptions: schema.GetThemeOptions,
+               Layout:       constant.ThemeLayoutFullWidth,
        }
        if err = s.GetSiteInfoByType(ctx, constant.SiteTypeTheme, resp); err != 
nil {
                return nil, err
        }
+       if resp.Layout == "" {
+               resp.Layout = constant.ThemeLayoutFullWidth
+       }
        resp.TrTheme(ctx)
        return resp, nil
 }

Reply via email to