Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Slug ¶
Slug returns a slugified string. The result will only contain lowercase letters, digits and dashes. It will not begin or end with a dash, and it will not contain runs of multiple dashes.
It is NOT forced into being ASCII, but may contain any Unicode characters, with the above restrictions.
Example ¶
package main
import (
"fmt"
"github.com/tv42/slug"
)
func main() {
fmt.Println(slug.Slug("Rødgrød med fløde"))
fmt.Println(slug.Slug("BUY NOW!!!11eleven"))
fmt.Println(slug.Slug("../../etc/passwd"))
}
Output: rødgrød-med-fløde buy-now-11eleven etc-passwd
func URL ¶
URL returns a slugified string based on the URL. In addition to the usual slugification rules, the following simplifications are done:
- schemes `http` and `https` are removed
- a leading `www.` in hostname is removed
- a trailing `/index.html` or `.html` is removed
func URLString ¶
URLString returns a slugified string based on the URL passed as a string. This is a convenience wrapper over URL. It fails only if parsing the URL fails.
Example ¶
package main
import (
"fmt"
"github.com/tv42/slug"
)
func main() {
s, err := slug.URLString("https://www.example.com/foo/index.html")
fmt.Println(s, err)
}
Output: example-com-foo <nil>
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.