Skip to content

Commit 7606940

Browse files
authored
Feat/1.3.0/UI (#840)
1 parent ebf5545 commit 7606940

File tree

46 files changed

+1921
-527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1921
-527
lines changed

i18n/en_US.yaml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,15 @@ ui:
11691169
system_setting: System setting
11701170
default: Default
11711171
reset: Reset
1172+
tag: Tag
1173+
post_lowercase: post
1174+
filter: Filter
1175+
ignore: Ignore
1176+
submit: Submit
1177+
normal: Normal
1178+
closed: Closed
1179+
deleted: Deleted
1180+
pending: Pending
11721181
search:
11731182
title: Search Results
11741183
keywords: Keywords
@@ -1444,6 +1453,7 @@ ui:
14441453
github: GitHub
14451454
blog: Blog
14461455
contact: Contact
1456+
forum: Forum
14471457
documents: Documents
14481458
feedback: Feedback
14491459
support: Support
@@ -1546,9 +1556,6 @@ ui:
15461556
content: A suspended user can't log in.
15471557
questions:
15481558
page_title: Questions
1549-
normal: Normal
1550-
closed: Closed
1551-
deleted: Deleted
15521559
unlisted: Unlisted
15531560
post: Post
15541561
votes: Votes
@@ -1557,12 +1564,11 @@ ui:
15571564
status: Status
15581565
action: Action
15591566
change: Change
1567+
pending: Pending
15601568
filter:
15611569
placeholder: "Filter by title, question:id"
15621570
answers:
15631571
page_title: Answers
1564-
normal: Normal
1565-
deleted: Deleted
15661572
post: Post
15671573
votes: Votes
15681574
created: Created
@@ -1676,8 +1682,8 @@ ui:
16761682
page_title: Write
16771683
restrict_answer:
16781684
title: Restrict answer
1679-
label: Each user can only write one answer for each question
1680-
text: "They can use the edit link to refine and improve their existing answer, instead."
1685+
label: Each user can only write one answer for the same question
1686+
text: "Turn off to allow users to write multiple answers to the same question, which may cause answers to be unfocused."
16811687
recommend_tags:
16821688
label: Recommend tags
16831689
text: "Please input tag slug above, one tag per line."
@@ -1811,6 +1817,22 @@ ui:
18111817
edit_answer: Edit answer
18121818
edit_tag: Edit tag
18131819
empty: No review tasks left.
1820+
approve_revision_tip: Do you approve this revision?
1821+
approve_flag_tip: Do you approve this flag?
1822+
approve_post_tip: Do you approve this post?
1823+
approve_user_tip: Do you approve this user?
1824+
suggest_edits: Suggested edits
1825+
flag_post: Flag post
1826+
flag_user: Flag user
1827+
queued_post: Queued post
1828+
queued_user: Queued user
1829+
filter_label: Type
1830+
reputation: reputation
1831+
flag_post_type: Flagged this post as {{ type }}
1832+
flag_user_type: Flagged this user as {{ type }}
1833+
edit_post: Edit post
1834+
list_post: List post
1835+
unlist_post: Unlist post
18141836
timeline:
18151837
undeleted: undeleted
18161838
deleted: deleted

i18n/zh_CN.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,15 @@ ui:
11331133
system_setting: System setting
11341134
default: Default
11351135
reset: Reset
1136+
tag: Tag
1137+
post_lowercase: 帖子
1138+
filter: Filter
1139+
ignore: 忽略
1140+
submit: 提交
1141+
normal: 正常
1142+
closed: 已关闭
1143+
deleted: 已删除
1144+
pending: Pending
11361145
search:
11371146
title: 搜索结果
11381147
keywords: 关键词
@@ -1631,8 +1640,8 @@ ui:
16311640
page_title: 编辑
16321641
restrict_answer:
16331642
title: 限制一个回答
1634-
label: 每个用户对于每个问题只能有一个回答
1635-
text: "用户可以使用编辑按钮优化已有的回答"
1643+
label: 每个用户只能为同一问题写一个回答
1644+
text: "关闭以允许用户对同一问题编写多个回答,这可能会导致回答不集中。"
16361645
recommend_tags:
16371646
label: 推荐标签
16381647
text: "请在上方输入标签固定链接,每行一个标签。"

internal/controller/template_controller.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ package controller
2222
import (
2323
"encoding/json"
2424
"fmt"
25-
"github.com/apache/incubator-answer/internal/entity"
2625
"html/template"
2726
"net/http"
2827
"regexp"
@@ -32,6 +31,7 @@ import (
3231
"github.com/apache/incubator-answer/internal/base/constant"
3332
"github.com/apache/incubator-answer/internal/base/handler"
3433
templaterender "github.com/apache/incubator-answer/internal/controller/template_render"
34+
"github.com/apache/incubator-answer/internal/entity"
3535
"github.com/apache/incubator-answer/internal/schema"
3636
"github.com/apache/incubator-answer/internal/service/siteinfo_common"
3737
"github.com/apache/incubator-answer/pkg/checker"
@@ -47,7 +47,7 @@ import (
4747
var SiteUrl = ""
4848

4949
type TemplateController struct {
50-
scriptPath string
50+
scriptPath []string
5151
cssPath string
5252
templateRenderController *templaterender.TemplateRenderController
5353
siteInfoService siteinfo_common.SiteInfoCommonService
@@ -66,18 +66,21 @@ func NewTemplateController(
6666
siteInfoService: siteInfoService,
6767
}
6868
}
69-
func GetStyle() (script, css string) {
69+
func GetStyle() (script []string, css string) {
7070
file, err := ui.Build.ReadFile("build/index.html")
7171
if err != nil {
7272
return
7373
}
74-
scriptRegexp := regexp.MustCompile(`<script defer="defer" src="(.*)"></script>`)
75-
scriptData := scriptRegexp.FindStringSubmatch(string(file))
74+
scriptRegexp := regexp.MustCompile(`<script defer="defer" src="([^"]*)"></script>`)
75+
scriptData := scriptRegexp.FindAllStringSubmatch(string(file), -1)
76+
for _, s := range scriptData {
77+
if len(s) == 2 {
78+
script = append(script, s[1])
79+
}
80+
}
81+
7682
cssRegexp := regexp.MustCompile(`<link href="(.*)" rel="stylesheet">`)
7783
cssListData := cssRegexp.FindStringSubmatch(string(file))
78-
if len(scriptData) == 2 {
79-
script = scriptData[1]
80-
}
8184
if len(cssListData) == 2 {
8285
css = cssListData[1]
8386
}

ui/config-overrides.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
const {
2121
addWebpackModuleRule,
2222
addWebpackAlias,
23+
setWebpackOptimizationSplitChunks,
2324
} = require("customize-cra");
2425

2526
const path = require("path");
@@ -37,6 +38,101 @@ module.exports = {
3738
use: "yaml-loader"
3839
})(config);
3940

41+
setWebpackOptimizationSplitChunks({
42+
maxInitialRequests: 20,
43+
minSize: 20 * 1024,
44+
minChunks: 2,
45+
cacheGroups: {
46+
automaticNamePrefix: 'chunk',
47+
components: {
48+
test: /[\\/]components[\\/]/,
49+
name: 'components',
50+
priority: 14,
51+
reuseExistingChunk: true,
52+
minChunks: 1,
53+
chunks: 'initial',
54+
},
55+
i18next: {
56+
name: 'i18next',
57+
test: /[\/]node_modules[\/](i18next)[\/]/,
58+
filename: 'static/js/[name].[contenthash:8].chunk.js',
59+
priority: 12,
60+
reuseExistingChunk: true,
61+
minChunks: 1,
62+
chunks: 'initial',
63+
},
64+
reactBootstrap: {
65+
name: 'react-bootstrap',
66+
test: /[\/]node_modules[\/](react-bootstrap)[\/]/,
67+
filename: 'static/js/[name].[contenthash:8].chunk.js',
68+
priority: 11,
69+
minChunks: 1,
70+
chunks: 'initial',
71+
reuseExistingChunk: true,
72+
},
73+
lodash: {
74+
name: 'lodash',
75+
test: /[\/]node_modules[\/](lodash)[\/]/,
76+
filename: 'static/js/[name].[contenthash:8].chunk.js',
77+
priority: 10,
78+
reuseExistingChunk: true,
79+
minChunks: 1,
80+
chunks: 'initial',
81+
},
82+
codemirror: {
83+
name: 'codemirror',
84+
test: /[\/]node_modules[\/](codemirror)[\/]/,
85+
priority: 9,
86+
reuseExistingChunk: true,
87+
enforce: true,
88+
},
89+
nextShare: {
90+
name: 'next-share',
91+
test: /[\/]node_modules[\/](next-share)[\/]/,
92+
filename: 'static/js/[name].[contenthash:8].chunk.js',
93+
priority: 8,
94+
reuseExistingChunk: true,
95+
minChunks: 1,
96+
chunks: 'initial',
97+
},
98+
marked: {
99+
name: 'marked',
100+
test: /[\/]node_modules[\/](marked)[\/]/,
101+
filename: 'static/js/[name].[contenthash:8].chunk.js',
102+
priority: 7,
103+
reuseExistingChunk: true,
104+
minChunks: 1,
105+
chunks: 'initial',
106+
},
107+
reactDom: {
108+
name: 'react-dom',
109+
test: /[\/]node_modules[\/](react-dom)[\/]/,
110+
filename: 'static/js/[name].[contenthash:8].chunk.js',
111+
priority: 7,
112+
reuseExistingChunk: true,
113+
chunks: 'all',
114+
enforce: true,
115+
},
116+
nodesAsync: {
117+
name: 'chunk-nodesAsync',
118+
test: /[\/]node_modules[\/]/,
119+
priority: 2,
120+
minChunks: 2,
121+
chunks: 'async', // 仅打包异步引用的依赖
122+
reuseExistingChunk: true, // 重复使用已经存在的块
123+
},
124+
nodesInitial: {
125+
name: 'chunk-nodesInitial',
126+
filename: 'static/js/[name].[contenthash:8].chunk.js',
127+
test: /[\/]node_modules[\/]/,
128+
priority: 1,
129+
minChunks: 1,
130+
chunks: 'initial',
131+
reuseExistingChunk: true,
132+
},
133+
},
134+
})(config);
135+
40136
// add i18n dir to ModuleScopePlugin allowedPaths
41137
const moduleScopePlugin = config.resolve.plugins.find(_ => _.constructor.name === "ModuleScopePlugin");
42138
if (moduleScopePlugin) {

ui/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"prepare": "pnpm build:packages",
1313
"pre-commit": "lint-staged",
1414
"build:packages": "pnpm -r --filter=./src/plugins/* run build",
15-
"clean": "rm -rf node_modules && rm -rf src/plugins/**/node_modules"
15+
"clean": "rm -rf node_modules && rm -rf src/plugins/**/node_modules",
16+
"analyze": "source-map-explorer 'build/static/js/*.js'"
1617
},
1718
"dependencies": {
1819
"axios": "^0.27.2",
@@ -82,6 +83,7 @@
8283
"react-app-rewired": "^2.2.1",
8384
"react-scripts": "5.0.1",
8485
"sass": "^1.54.4",
86+
"source-map-explorer": "^2.5.3",
8587
"typescript": "^4.9.5",
8688
"yaml-loader": "^0.8.0"
8789
},

0 commit comments

Comments
 (0)