Skip to content

Commit

Permalink
Catch typos: ignore dashes and whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuswilms committed Mar 21, 2018
1 parent cd2f333 commit bfa667b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ var (
// Basenames matching this pattern are considered documents.
NodeDocsRegexp = regexp.MustCompile(`(?i)^.*\.(md|markdown|html?)$`)

// Characters that are ignored when looking up an URL,
// i.e. "foo/bar baz" and "foo/barbaz" are than equal.
NodeLookupURLIgnoreChars = regexp.MustCompile(`[\s\-_]+`)

// 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.
Expand Down Expand Up @@ -117,7 +121,10 @@ func (n Node) UnnormalizedURL() string {

// Returns the normalized and lower cased lookup URL for this node.
func (n Node) LookupURL() string {
return strings.ToLower(n.URL())
return NodeLookupURLIgnoreChars.ReplaceAllString(
strings.ToLower(n.URL()),
"",
)
}

// An order number, as a hint for outside sorting mechanisms.
Expand Down Expand Up @@ -338,7 +345,10 @@ func normalizeNodeURL(url string) string {
}

func lookupNodeURL(url string) string {
return strings.ToLower(normalizeNodeURL(url))
return NodeLookupURLIgnoreChars.ReplaceAllString(
strings.ToLower(normalizeNodeURL(url)),
"",
)
}

// Finds an order number embedded into given path/URL segment and
Expand Down

0 comments on commit bfa667b

Please sign in to comment.