Skip to content

Commit

Permalink
refactor(gomod): replace pinyin dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkinStars committed Sep 26, 2024
1 parent f8fd872 commit 6817faf
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/release/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
9 changes: 2 additions & 7 deletions internal/service/user_common/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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, " ", "-")
Expand Down
11 changes: 3 additions & 8 deletions pkg/htmltext/htmltext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6817faf

Please sign in to comment.