Skip to content

Commit b5ae2d0

Browse files
author
shuai
committed
fix: admin/themes add layout config
1 parent 5940877 commit b5ae2d0

13 files changed

Lines changed: 72 additions & 82 deletions

File tree

cmd/wire_gen.go

Lines changed: 2 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
/*
2-
* Licensed to the Apache Software Foundation (ASF) under one
3-
* or more contributor license agreements. See the NOTICE file
4-
* distributed with this work for additional information
5-
* regarding copyright ownership. The ASF licenses this file
6-
* to you under the Apache License, Version 2.0 (the
7-
* "License"); you may not use this file except in compliance
8-
* with the License. You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
12-
* Unless required by applicable law or agreed to in writing,
13-
* software distributed under the License is distributed on an
14-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15-
* KIND, either express or implied. See the License for the
16-
* specific language governing permissions and limitations
17-
* under the License.
18-
*/
19-
201
// Package docs Code generated by swaggo/swag. DO NOT EDIT
212
package docs
223

docs/swagger.yaml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
# Licensed to the Apache Software Foundation (ASF) under one
2-
# or more contributor license agreements. See the NOTICE file
3-
# distributed with this work for additional information
4-
# regarding copyright ownership. The ASF licenses this file
5-
# to you under the Apache License, Version 2.0 (the
6-
# "License"); you may not use this file except in compliance
7-
# with the License. You may obtain a copy of the License at
8-
#
9-
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
11-
# Unless required by applicable law or agreed to in writing,
12-
# software distributed under the License is distributed on an
13-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14-
# KIND, either express or implied. See the License for the
15-
# specific language governing permissions and limitations
16-
# under the License.
17-
181
basePath: /
192
definitions:
203
constant.NotificationChannelKey:

i18n/en_US.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,6 +2186,10 @@ ui:
21862186
primary_color:
21872187
label: Primary color
21882188
text: Modify the colors used by your themes
2189+
layout:
2190+
label: Layout
2191+
full_width: Full-width
2192+
fixed_width: Fixed-width
21892193
css_and_html:
21902194
page_title: CSS and HTML
21912195
custom_css:

internal/service/mock/siteinfo_repo_mock.go

Lines changed: 0 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/src/common/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ export type themeConfig = {
469469
export interface AdminSettingsTheme {
470470
theme: string;
471471
color_scheme: string;
472+
layout: string;
472473
theme_options?: { label: string; value: string }[];
473474
theme_config: Record<string, themeConfig>;
474475
}

ui/src/components/Customize/index.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
import { FC, memo, useEffect } from 'react';
21+
import { useLocation } from 'react-router-dom';
2122

2223
import { customizeStore } from '@/stores';
2324

@@ -117,6 +118,8 @@ const Index: FC = () => {
117118
const { custom_head, custom_header, custom_footer } = customizeStore(
118119
(state) => state,
119120
);
121+
const { pathname } = useLocation();
122+
120123
useEffect(() => {
121124
const isSeo = document.querySelector('meta[name="go-template"]');
122125
if (!isSeo) {
@@ -125,8 +128,41 @@ const Index: FC = () => {
125128
}, 1000);
126129
handleCustomHeader(custom_header);
127130
handleCustomFooter(custom_footer);
131+
} else {
132+
isSeo.remove();
128133
}
129134
}, [custom_head, custom_header, custom_footer]);
135+
136+
useEffect(() => {
137+
/**
138+
* description: Activate scripts with data-client attribute when route changes
139+
*/
140+
const allScript = document.body.querySelectorAll('script[data-client]');
141+
console.log('allScript', allScript);
142+
allScript.forEach((scriptNode) => {
143+
const script = document.createElement('script');
144+
script.setAttribute('data-client', 'true');
145+
// If the script is already wrapped in an IIFE, use it directly; otherwise, wrap it in an IIFE
146+
if (
147+
/^\s*\(\s*function\s*\(\s*\)\s*{/.test(
148+
(scriptNode as HTMLScriptElement).text,
149+
) ||
150+
/^\s*\(\s*\(\s*\)\s*=>\s*{/.test((scriptNode as HTMLScriptElement).text)
151+
) {
152+
script.text = (scriptNode as HTMLScriptElement).text;
153+
} else {
154+
script.text = `(() => {${(scriptNode as HTMLScriptElement).text}})();`;
155+
}
156+
for (let i = 0; i < scriptNode.attributes.length; i += 1) {
157+
const attr = scriptNode.attributes[i];
158+
if (attr.name !== 'data-client') {
159+
script.setAttribute(attr.name, attr.value);
160+
}
161+
}
162+
scriptNode.parentElement?.replaceChild(script, scriptNode);
163+
});
164+
}, [pathname]);
165+
130166
return null;
131167
};
132168

ui/src/components/Header/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const Header: FC = () => {
8383

8484
let navbarStyle = 'theme-light';
8585
let themeMode = 'light';
86-
const { theme, theme_config } = themeSettingStore((_) => _);
86+
const { theme, theme_config, layout } = themeSettingStore((_) => _);
8787
if (theme_config?.[theme]?.navbar_style) {
8888
// const color = theme_config[theme].navbar_style.startsWith('#')
8989
themeMode = isLight(theme_config[theme].navbar_style) ? 'light' : 'dark';
@@ -113,7 +113,11 @@ const Header: FC = () => {
113113
backgroundColor: theme_config[theme].navbar_style,
114114
}}
115115
id="header">
116-
<div className="w-100 d-flex align-items-center px-3">
116+
<div
117+
className={classnames(
118+
'w-100 d-flex align-items-center px-3',
119+
layout === 'Fixed-width' ? 'container-xxl' : '',
120+
)}>
117121
<Navbar.Toggle
118122
className="answer-navBar me-2"
119123
onClick={() => {

ui/src/pages/Admin/Themes/index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ const Index: FC = () => {
4646
enumNames: themeSetting?.theme_options?.map((_) => _.label),
4747
default: themeSetting?.theme_options?.[0]?.value,
4848
},
49+
layout: {
50+
type: 'string',
51+
title: t('layout.label'),
52+
enum: ['Full-width', 'Fixed-width'],
53+
enumNames: [t('layout.full_width'), t('layout.fixed_width')],
54+
default: themeSetting?.layout,
55+
},
4956
color_scheme: {
5057
type: 'string',
5158
title: t('color_scheme.label'),
@@ -77,6 +84,9 @@ const Index: FC = () => {
7784
color_scheme: {
7885
'ui:widget': 'select',
7986
},
87+
layout: {
88+
'ui:widget': 'select',
89+
},
8090
navbar_style: {
8191
'ui:widget': 'input_group',
8292
'ui:options': {
@@ -131,6 +141,7 @@ const Index: FC = () => {
131141
const reqParams: Type.AdminSettingsTheme = {
132142
theme: themeName,
133143
color_scheme: formData.color_scheme.value,
144+
layout: formData.layout.value,
134145
theme_config: {
135146
[themeName]: {
136147
navbar_style: formData.navbar_style.value,

0 commit comments

Comments
 (0)