mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-16 20:53:59 +02:00
committed by
Bjørn Erik Pedersen
parent
8999de193c
commit
fff132537b
@@ -74,6 +74,35 @@ func (filepathBridge) Separator() string {
|
||||
|
||||
var fpb filepathBridge
|
||||
|
||||
// segmentReplacer replaces some URI-reserved characters in a path segments.
|
||||
var segmentReplacer = strings.NewReplacer("/", "-", "#", "-")
|
||||
|
||||
// MakeSegment returns a copy of string s that is appropriate for a path
|
||||
// segment. MakeSegment is similar to MakePath but disallows the '/' and
|
||||
// '#' characters because of their reserved meaning in URIs.
|
||||
func (p *PathSpec) MakeSegment(s string) string {
|
||||
s = p.MakePathSanitized(strings.Trim(segmentReplacer.Replace(s), "- "))
|
||||
|
||||
var pos int
|
||||
var last byte
|
||||
b := make([]byte, len(s))
|
||||
|
||||
for i := 0; i < len(s); i++ {
|
||||
// consolidate dashes
|
||||
if s[i] == '-' && last == '-' {
|
||||
continue
|
||||
}
|
||||
|
||||
b[pos], last = s[i], s[i]
|
||||
pos++
|
||||
}
|
||||
|
||||
if p.DisablePathToLower {
|
||||
return string(b[:pos])
|
||||
}
|
||||
return strings.ToLower(string(b[:pos]))
|
||||
}
|
||||
|
||||
// MakePath takes a string with any characters and replace it
|
||||
// so the string could be used in a path.
|
||||
// It does so by creating a Unicode-sanitized string, with the spaces replaced,
|
||||
|
Reference in New Issue
Block a user