gosimple/slug 是一个golang 包,可以用开生成支持多语言的url 友好的slug

参考使用

package main
import (
    "fmt"
    "github.com/gosimple/slug"
)
func main() {
    text := slug.Make("Hellö Wörld хелло ворлд")
    fmt.Println(text) // Will print: "hello-world-khello-vorld"
    someText := slug.Make("影師")
    fmt.Println(someText) // Will print: "ying-shi"
    enText := slug.MakeLang("This & that", "en")
    fmt.Println(enText) // Will print: "this-and-that"
    deText := slug.MakeLang("Diese & Dass", "de")
    fmt.Println(deText) // Will print: "diese-und-dass"
    slug.Lowercase = false // Keep uppercase characters
    deUppercaseText := slug.MakeLang("Diese & Dass", "de")
        fmt.Println(deUppercaseText) // Will print: "Diese-und-Dass"
    slug.CustomSub = map[string]string{
        "water": "sand",
    }
    textSub := slug.Make("water is hot")
    fmt.Println(textSub) // Will print: "sand-is-hot"
}

说明

好多项目都依赖了gosimple/slug ,而且如果我们是做cms 使用此包生成url 也是一个不错的

参考资料

https://github.com/gosimple/slug

相关文章:

  • 2021-10-25
  • 2022-02-17
  • 2021-11-25
  • 2022-12-23
  • 2021-06-09
  • 2022-12-23
  • 2021-12-24
猜你喜欢
  • 2021-10-27
  • 2022-02-20
  • 2022-12-23
  • 2021-06-04
  • 2021-11-11
  • 2021-09-04
  • 2022-12-23
相关资源
相似解决方案