Skip to content

Commit

Permalink
Use library for slugging urls
Browse files Browse the repository at this point in the history
For better handling of umlauts (#53)
  • Loading branch information
ChristophLabacher committed Sep 7, 2018
1 parent 5513bd9 commit c7b44a6
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/fatih/color"
"github.com/gosimple/slug"
"golang.org/x/text/unicode/norm"
)

Expand All @@ -41,9 +42,7 @@ var (
// Patterns for extracting order number and title from a node's
// path/URL segment in the form of 06_Foo. As well as for
// "slugging" the URL/path segment.
NodePathTitleRegexp = regexp.MustCompile(`^0?(\d+)[_,-]+(.*)$`)
NodePathInvalidCharsRegexp = regexp.MustCompile(`[^A-Za-z0-9-_]`)
NodePathMultipleDashRegexp = regexp.MustCompile(`-+`)
NodePathTitleRegexp = regexp.MustCompile(`^0?(\d+)[_,-]+(.*)$`)
)

// Constructs a new node using its path in the filesystem. Returns a
Expand Down Expand Up @@ -417,9 +416,7 @@ func normalizeNodeURL(url string) string {
}
p = norm.NFC.String(p)
p = removeOrderNumber(p)
p = NodePathInvalidCharsRegexp.ReplaceAllString(p, "-")
p = NodePathMultipleDashRegexp.ReplaceAllString(p, "-")
p = strings.Trim(p, "-")
p = slug.Make(p)

normalized = append(normalized, p)
}
Expand Down

0 comments on commit c7b44a6

Please sign in to comment.