Added cj & jyutping lookup

This commit is contained in:
2026-02-20 12:41:04 +08:00
parent 59d5934097
commit f6c9e40540
21 changed files with 114450 additions and 139 deletions

View File

@@ -0,0 +1,32 @@
package cjlookup
import (
"fmt"
"log"
"net/url"
"golang.org/x/text/encoding/traditionalchinese"
)
var CUHARTS_FACE = "[%s](https://humanum.arts.cuhk.edu.hk/Lexis/lexi-can/search.php?q=%s)"
var ZDIC_FACE = "[%s](https://www.zdic.net/hans/%s)"
func getCUHARTSUrlForChar(c string) string {
b, err := Big5UrlParam(c)
if err != nil {
log.Printf("Failed to encode:", c, err)
return fmt.Sprintf(ZDIC_FACE, c, c)
}
return fmt.Sprintf(CUHARTS_FACE, c, b)
}
func Big5UrlParam(input string) (string, error) {
enc := traditionalchinese.Big5.NewEncoder()
encodedBytes, err := enc.Bytes([]byte(input))
if err != nil {
return "", err
}
urlEncoded := url.PathEscape(string(encodedBytes))
return urlEncoded, nil
}