chore: optimize SEO and fix golangci-lint issues
- Implement dynamic SEO meta tags and sitemap.xml for toolbox.pengzhan.dev - Fix SPA title/meta refresh issue in layout.html - Address golangci-lint findings: - Refactor switch-case for tool path and SVG token parsing - Replace math.Pow with direct multiplication for performance - Fix unhandled error returns and unused imports - Omit redundant type declarations
This commit is contained in:
+37
-20
@@ -28,10 +28,12 @@ func init() {
|
||||
base.Register(&zitieTool{})
|
||||
}
|
||||
|
||||
func (t *zitieTool) ID() string { return "zitie" }
|
||||
func (t *zitieTool) Name() string { return "汉字字帖生成" }
|
||||
func (t *zitieTool) Description() string { return "提供智能缺字处理和古风排版的专业字帖工具" }
|
||||
func (t *zitieTool) Emoji() string { return "🎨" }
|
||||
func (t *zitieTool) ID() string { return "zitie" }
|
||||
func (t *zitieTool) Name() string { return "汉字字帖生成" }
|
||||
func (t *zitieTool) Description() string {
|
||||
return "提供智能缺字处理和古风排版的专业字帖工具"
|
||||
}
|
||||
func (t *zitieTool) Emoji() string { return "🎨" }
|
||||
|
||||
func (t *zitieTool) Init() error {
|
||||
fmt.Println("Initializing Zitie tool with font check...")
|
||||
@@ -39,21 +41,23 @@ func (t *zitieTool) Init() error {
|
||||
if err := json.Unmarshal(allDataContent, &t.allChars); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal all.json: %v", err)
|
||||
}
|
||||
|
||||
|
||||
fontBytes, _ := fontFS.ReadFile("data/font.ttf")
|
||||
logic.SetFontData(fontBytes)
|
||||
|
||||
fonts := map[string]string{
|
||||
"kaiti": "data/kaiti.ttf",
|
||||
"lishu": "data/lishu.ttf",
|
||||
"xingshu": "data/xingshu.ttf",
|
||||
"songti": "data/songti.ttf",
|
||||
"kaiti": "data/kaiti.ttf",
|
||||
"lishu": "data/lishu.ttf",
|
||||
"xingshu": "data/xingshu.ttf",
|
||||
"songti": "data/songti.ttf",
|
||||
}
|
||||
|
||||
for id, src := range fonts {
|
||||
bytes, err := fontFS.ReadFile(src)
|
||||
if err != nil { continue }
|
||||
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// 1. 同步到磁盘用于 gopdf
|
||||
tmpPath := filepath.Join(os.TempDir(), fmt.Sprintf("own_tools_%s.ttf", id))
|
||||
_ = os.WriteFile(tmpPath, bytes, 0644)
|
||||
@@ -66,7 +70,7 @@ func (t *zitieTool) Init() error {
|
||||
fmt.Printf("Font [%s] analyzed and registered\n", id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -79,7 +83,7 @@ func (t *zitieTool) RegisterRoutes(r *gin.RouterGroup) {
|
||||
type ZitieRequest struct {
|
||||
Chars string `json:"chars" binding:"required"`
|
||||
PaperSize string `json:"paper_size"`
|
||||
FontType string `json:"font_type"`
|
||||
FontType string `json:"font_type"`
|
||||
}
|
||||
|
||||
func (t *zitieTool) handleTeaching(c *gin.Context) {
|
||||
@@ -108,7 +112,9 @@ func (t *zitieTool) handleManuscript(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if req.FontType == "" { req.FontType = "kaiti" }
|
||||
if req.FontType == "" {
|
||||
req.FontType = "kaiti"
|
||||
}
|
||||
data := t.filterChars(req.Chars, true)
|
||||
t.generateAndResponse(c, data, "manuscript", req.PaperSize, req.FontType)
|
||||
}
|
||||
@@ -117,18 +123,29 @@ func (t *zitieTool) filterChars(input string, keepNewline bool) []logic.HanziDat
|
||||
var res []logic.HanziData
|
||||
// 扩充标点符号列表
|
||||
puncs := ",。!?;:、“”()《》〈〉…·.?!,:;\"'()<> 「」【】『』〔〕"
|
||||
|
||||
|
||||
for _, r := range input {
|
||||
charStr := string(r)
|
||||
if r == '\n' {
|
||||
if keepNewline { res = append(res, logic.HanziData{Character: "\n"}) }
|
||||
if keepNewline {
|
||||
res = append(res, logic.HanziData{Character: "\n"})
|
||||
}
|
||||
continue
|
||||
}
|
||||
if r == ' ' || r == '\r' || r == '\t' { continue }
|
||||
|
||||
if r == ' ' || r == '\r' || r == '\t' {
|
||||
continue
|
||||
}
|
||||
|
||||
isPunc := false
|
||||
for _, p := range puncs { if r == p { isPunc = true; break } }
|
||||
if isPunc { continue }
|
||||
for _, p := range puncs {
|
||||
if r == p {
|
||||
isPunc = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if isPunc {
|
||||
continue
|
||||
}
|
||||
|
||||
if hd, ok := t.allChars[charStr]; ok {
|
||||
hd.Character = charStr
|
||||
|
||||
Reference in New Issue
Block a user