♻️ refactor(handlers): status 与 review 页面模板化
- HTML 提取至 templates/status.html、templates/review.html(go:embed 内嵌) - status.go 1022→271 行、review.go 1281→438 行,动态数据全部经 html/template 按上下文自动转义 - 评论循环/作者徽章/贴纸/图片条件渲染翻译为模板 range/if;emojiMap 以 template.JS 注入 - 与旧版渲染输出实测对比:22 条评论结构完全一致;差异仅为 JS 上下文安全转义(& 等)与 html/template 剥除 CSS 注释,均无功能影响 - 其余文件为 gofmt 顺手格式化
This commit is contained in:
1 parent
ad6d28fd85
commit
5bcc8a962e
29 files changed
+1267
-2893
No files matched your search
@@ -57,10 +57,10 @@ func removeBlankLines(content string) string {
|
||||
for strings.Contains(content, "\n\n\n") {
|
||||
content = strings.ReplaceAll(content, "\n\n\n", "\n\n")
|
||||
}
|
||||
|
||||
|
||||
// 移除首尾的空白
|
||||
content = strings.TrimSpace(content)
|
||||
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
@@ -127,22 +127,22 @@ func BuildURL(fullURL string, customParams ...string) string {
|
||||
"os_version=0",
|
||||
"version_code=58932",
|
||||
}
|
||||
|
||||
|
||||
// 添加设备header
|
||||
header := getDeviceHeader()
|
||||
if header != "" {
|
||||
allParams = append(allParams, header)
|
||||
}
|
||||
|
||||
|
||||
// 添加自定义参数
|
||||
allParams = append(allParams, customParams...)
|
||||
|
||||
|
||||
// 合并、拆分、排序
|
||||
joined := strings.Join(allParams, "&")
|
||||
paramList := strings.Split(joined, "&")
|
||||
sort.Strings(paramList)
|
||||
params := strings.Join(paramList, "&")
|
||||
|
||||
|
||||
return fullURL + "?" + params
|
||||
}
|
||||
|
||||
@@ -218,11 +218,11 @@ func parseStringToInt(s string) (int, error) {
|
||||
// 简单实现,避免导入strconv
|
||||
result := 0
|
||||
negative := false
|
||||
|
||||
|
||||
if len(s) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
|
||||
start := 0
|
||||
if s[0] == '-' {
|
||||
negative = true
|
||||
@@ -230,18 +230,18 @@ func parseStringToInt(s string) (int, error) {
|
||||
} else if s[0] == '+' {
|
||||
start = 1
|
||||
}
|
||||
|
||||
|
||||
for i := start; i < len(s); i++ {
|
||||
if s[i] < '0' || s[i] > '9' {
|
||||
break
|
||||
}
|
||||
result = result*10 + int(s[i]-'0')
|
||||
}
|
||||
|
||||
|
||||
if negative {
|
||||
result = -result
|
||||
}
|
||||
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ func ParseStringParam(param interface{}, defaultVal string) string {
|
||||
if param == nil || param == "" {
|
||||
return defaultVal
|
||||
}
|
||||
|
||||
|
||||
switch v := param.(type) {
|
||||
case string:
|
||||
if v != "" {
|
||||
@@ -262,4 +262,3 @@ func ParseStringParam(param interface{}, defaultVal string) string {
|
||||
}
|
||||
return defaultVal
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user