This is an automated email from the ASF dual-hosted git repository.

robin0716 pushed a commit to branch test
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit 6817fafcca55343070f0b677c2692a258eda0796
Author: LinkinStars <[email protected]>
AuthorDate: Thu Sep 26 16:25:00 2024 +0800

    refactor(gomod): replace pinyin dependency
---
 docs/release/LICENSE                                          |  2 +-
 ...Chain-Zhang-pinyin.txt => LICENSE-mozillazg-go-pinyin.txt} |  4 ++--
 go.mod                                                        |  2 +-
 go.sum                                                        |  4 ++--
 internal/service/user_common/user.go                          |  9 ++-------
 pkg/htmltext/htmltext.go                                      | 11 +++--------
 6 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/docs/release/LICENSE b/docs/release/LICENSE
index 26c12b2b..65e5642d 100644
--- a/docs/release/LICENSE
+++ b/docs/release/LICENSE
@@ -246,7 +246,7 @@ The following components are provided under the MIT 
License. See project link fo
    (MIT License) react-router (https://github.com/remix-run/react-router) 
[link](./licenses/LICENSE-remix-run-react-router.txt)
    (MIT License) swr (https://github.com/vercel/swr) 
[link](./licenses/LICENSE-vercel-swr.txt)
    (MIT License) zustand (https://github.com/pmndrs/zustand) 
[link](./licenses/LICENSE-pmndrs-zustand.txt)
-   (MIT License) Chain-Zhang-pinyin (https://github.com/Chain-Zhang/pinyin) 
[link](./licenses/LICENSE-Chain-Zhang-pinyin.txt)
+   (MIT License) mozillazg-go-pinyin (https://github.com/mozillazg/go-pinyin) 
[link](./licenses/LICENSE-mozillazg-go-pinyin.txt)
    (MIT License) Machiel-slugify (https://github.com/Machiel/slugify) 
[link](./licenses/LICENSE-Machiel-slugify.txt)
    (MIT License) Masterminds-semver (https://github.com/Masterminds/semver) 
[link](./licenses/LICENSE-Masterminds-semver.txt)
    (MIT License) anargu-gin-brotli (https://github.com/anargu/gin-brotli) 
[link](./licenses/LICENSE-anargu-gin-brotli.txt)
diff --git a/docs/release/licenses/LICENSE-Chain-Zhang-pinyin.txt 
b/docs/release/licenses/LICENSE-mozillazg-go-pinyin.txt
similarity index 95%
rename from docs/release/licenses/LICENSE-Chain-Zhang-pinyin.txt
rename to docs/release/licenses/LICENSE-mozillazg-go-pinyin.txt
index c98d6a49..8a7780fc 100644
--- a/docs/release/licenses/LICENSE-Chain-Zhang-pinyin.txt
+++ b/docs/release/licenses/LICENSE-mozillazg-go-pinyin.txt
@@ -1,6 +1,6 @@
-MIT License
+The MIT License (MIT)
 
-Copyright (c) 2019 Chain Zhang
+Copyright (c) 2016 mozillazg
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/go.mod b/go.mod
index 615b0f73..84689ef9 100644
--- a/go.mod
+++ b/go.mod
@@ -20,7 +20,6 @@ module github.com/apache/incubator-answer
 go 1.22.0
 
 require (
-       github.com/Chain-Zhang/pinyin v0.1.3
        github.com/Machiel/slugify v1.0.1
        github.com/Masterminds/semver/v3 v3.3.0
        github.com/anargu/gin-brotli v0.0.0-20220116052358-12bf532d5267
@@ -41,6 +40,7 @@ require (
        github.com/jinzhu/now v1.1.5
        github.com/lib/pq v1.10.9
        github.com/microcosm-cc/bluemonday v1.0.27
+       github.com/mozillazg/go-pinyin v0.20.0
        github.com/ory/dockertest/v3 v3.11.0
        github.com/robfig/cron/v3 v3.0.1
        github.com/scottleedavis/go-exif-remove 
v0.0.0-20230314195146-7e059d593405
diff --git a/go.sum b/go.sum
index 1a2ab6fc..c8e314f1 100644
--- a/go.sum
+++ b/go.sum
@@ -8,8 +8,6 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 
h1:L/gRVlceqvL25
 github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod 
h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
 github.com/BurntSushi/toml v1.0.0 
h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
 github.com/BurntSushi/toml v1.0.0/go.mod 
h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
-github.com/Chain-Zhang/pinyin v0.1.3 
h1:RzErNyNwVa8z2sOLCuXSOtVdY/AsARb8mBzI2p2qtnE=
-github.com/Chain-Zhang/pinyin v0.1.3/go.mod 
h1:5iHpt9p4znrnaP59/hfPMnAojajkDxQaP9io+tRMPho=
 github.com/KyleBanks/depth v1.2.1 
h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
 github.com/KyleBanks/depth v1.2.1/go.mod 
h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
 github.com/LinkinStars/go-i18n/v2 v2.2.2 
h1:ZfjpzbW13dv6btv3RALKZkpN9A+7K1JA//2QcNeWaxU=
@@ -241,6 +239,8 @@ github.com/modern-go/concurrent 
v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
 github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod 
h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
 github.com/modern-go/reflect2 v1.0.2 
h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
 github.com/modern-go/reflect2 v1.0.2/go.mod 
h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
+github.com/mozillazg/go-pinyin v0.20.0 
h1:BtR3DsxpApHfKReaPO1fCqF4pThRwH9uwvXzm+GnMFQ=
+github.com/mozillazg/go-pinyin v0.20.0/go.mod 
h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc=
 github.com/ncruces/go-strftime v0.1.9 
h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
 github.com/ncruces/go-strftime v0.1.9/go.mod 
h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
 github.com/onsi/ginkgo v1.6.0/go.mod 
h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
diff --git a/internal/service/user_common/user.go 
b/internal/service/user_common/user.go
index a10c4766..7980044e 100644
--- a/internal/service/user_common/user.go
+++ b/internal/service/user_common/user.go
@@ -26,7 +26,6 @@ import (
        "github.com/apache/incubator-answer/internal/base/constant"
        "github.com/apache/incubator-answer/pkg/converter"
 
-       "github.com/Chain-Zhang/pinyin"
        "github.com/apache/incubator-answer/internal/base/reason"
        "github.com/apache/incubator-answer/internal/entity"
        "github.com/apache/incubator-answer/internal/schema"
@@ -35,6 +34,7 @@ import (
        "github.com/apache/incubator-answer/internal/service/siteinfo_common"
        "github.com/apache/incubator-answer/pkg/checker"
        "github.com/apache/incubator-answer/pkg/random"
+       "github.com/mozillazg/go-pinyin"
        "github.com/segmentfault/pacman/errors"
        "github.com/segmentfault/pacman/log"
 )
@@ -181,12 +181,7 @@ func (us *UserCommon) FormatUserBasicInfo(ctx 
context.Context, userInfo *entity.
 func (us *UserCommon) MakeUsername(ctx context.Context, displayName string) 
(username string, err error) {
        // Chinese processing
        if has := checker.IsChinese(displayName); has {
-               str, err := 
pinyin.New(displayName).Split("").Mode(pinyin.WithoutTone).Convert()
-               if err != nil {
-                       return "", errors.BadRequest(reason.UsernameInvalid)
-               } else {
-                       displayName = str
-               }
+               displayName = strings.Join(pinyin.LazyConvert(displayName, 
nil), "")
        }
 
        username = strings.ReplaceAll(displayName, " ", "-")
diff --git a/pkg/htmltext/htmltext.go b/pkg/htmltext/htmltext.go
index a72f9b5c..77ca2fba 100644
--- a/pkg/htmltext/htmltext.go
+++ b/pkg/htmltext/htmltext.go
@@ -27,12 +27,11 @@ import (
        "strings"
        "unicode/utf8"
 
-       "github.com/Chain-Zhang/pinyin"
        "github.com/Machiel/slugify"
-       strip "github.com/grokify/html-strip-tags-go"
-
        "github.com/apache/incubator-answer/pkg/checker"
        "github.com/apache/incubator-answer/pkg/converter"
+       strip "github.com/grokify/html-strip-tags-go"
+       "github.com/mozillazg/go-pinyin"
 )
 
 // ClearText clear HTML, get the clear text
@@ -97,11 +96,7 @@ func convertChinese(content string) string {
        if !has {
                return content
        }
-       str, err := 
pinyin.New(content).Split("-").Mode(pinyin.WithoutTone).Convert()
-       if err != nil {
-               return content
-       }
-       return str
+       return strings.Join(pinyin.LazyConvert(content, nil), "-")
 }
 
 func cutLongTitle(title string) string {

Reply via email to