feat(ingestion): add wiki package with Page types and slug generation
This commit is contained in:
28
ingestion/internal/wiki/slug.go
Normal file
28
ingestion/internal/wiki/slug.go
Normal file
@@ -0,0 +1,28 @@
|
||||
// ingestion/internal/wiki/slug.go
|
||||
package wiki
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// Slug converts a title to a kebab-case slug suitable for wiki filenames.
|
||||
// Rules: lowercase, spaces/hyphens/underscores → hyphens, strip everything else.
|
||||
func Slug(title string) string {
|
||||
var b strings.Builder
|
||||
prevHyphen := true // start true to trim leading hyphens
|
||||
for _, r := range strings.ToLower(title) {
|
||||
switch {
|
||||
case r == ' ' || r == '-' || r == '_':
|
||||
if !prevHyphen {
|
||||
b.WriteRune('-')
|
||||
prevHyphen = true
|
||||
}
|
||||
case unicode.IsLetter(r) || unicode.IsDigit(r):
|
||||
b.WriteRune(r)
|
||||
prevHyphen = false
|
||||
// all other characters (apostrophes, colons, dots, etc.) are dropped
|
||||
}
|
||||
}
|
||||
return strings.TrimRight(b.String(), "-")
|
||||
}
|
||||
Reference in New Issue
Block a user