upgrade: 优化文档主题处理

This commit is contained in:
2025-08-23 09:26:29 +08:00
parent 90ca1f853f
commit a3b0c5f701
20 changed files with 22 additions and 10 deletions

View File

@ -8,7 +8,6 @@
package api_doc
import (
"embed"
"fmt"
"net/http"
"path/filepath"
@ -16,6 +15,7 @@ import (
"git.zhangdeman.cn/gateway/api-doc/define"
"git.zhangdeman.cn/gateway/api-doc/enums"
"git.zhangdeman.cn/gateway/api-doc/theme"
"git.zhangdeman.cn/zhangdeman/consts"
"github.com/gin-gonic/gin"
knife4goFiles "github.com/go-webtools/knife4go"
@ -24,12 +24,6 @@ import (
ginSwagger "github.com/swaggo/gin-swagger"
)
//go:embed ydoc-lucky-ui/*
var ydocUIFiles embed.FS
//go:embed redoc-free/index.html
var redocFreeIndexContent string
// NewSwaggerUI ...
func NewSwaggerUI(info *define.Info, servers []*define.ServerItem, uiTheme enums.SwaggerUITheme) *SwaggerUI {
return &SwaggerUI{
@ -112,7 +106,7 @@ func (su *SwaggerUI) HandleLuckyUI() func(ctx *gin.Context) {
// su.router.StaticFS(su.baseUri+"/assets", http.FS(ydocUIFiles))
return func(ctx *gin.Context) {
fileRealPath := strings.TrimPrefix(ctx.Request.RequestURI, su.baseUri)
byteData, _ := ydocUIFiles.ReadFile(filepath.Join(enums.SwaggerUIThemeYDocLucky.String(), fileRealPath))
byteData, _ := theme.YdocUIFiles.ReadFile(filepath.Join(enums.SwaggerUIThemeYDocLucky.String(), fileRealPath))
if strings.HasSuffix(ctx.Request.RequestURI, "html") {
byteData = []byte(strings.ReplaceAll(string(byteData), "{{BASE_URI}}", su.baseUri))
}
@ -156,10 +150,10 @@ func (su *SwaggerUI) HandleRedocFreeUI() func(ctx *gin.Context) {
"{{REDOC_STANDALONE_JS}}": "https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js",
}
for k, v := range replaceTable {
redocFreeIndexContent = strings.ReplaceAll(redocFreeIndexContent, k, v)
theme.RedocFreeIndexContent = strings.ReplaceAll(theme.RedocFreeIndexContent, k, v)
}
ctx.Header(consts.HeaderKeyContentType.String(), "text/html; charset=utf-8")
ctx.String(http.StatusOK, redocFreeIndexContent)
ctx.String(http.StatusOK, theme.RedocFreeIndexContent)
ctx.Abort()
}
}

16
theme/embed.go Normal file
View File

@ -0,0 +1,16 @@
// Package theme ...
//
// Description : theme ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2025-08-23 09:23
package theme
import "embed"
//go:embed ydoc-lucky-ui/*
var YdocUIFiles embed.FS
//go:embed redoc-free/index.html
var RedocFreeIndexContent string

View File

Before

Width:  |  Height:  |  Size: 156 B

After

Width:  |  Height:  |  Size: 156 B

View File

Before

Width:  |  Height:  |  Size: 340 KiB

After

Width:  |  Height:  |  Size: 340 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -10,6 +10,8 @@ package util
import (
"net/http"
"strings"
"git.zhangdeman.cn/zhangdeman/consts"
)
// GetParameterDefaultLocation 获取参数的默认位置