feat(ingestion): add wiki package with Page types and slug generation

This commit is contained in:
Mathias Bergqvist
2026-04-22 22:25:45 +02:00
parent c7341a2607
commit 91e02b930c
3 changed files with 81 additions and 0 deletions

View 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(), "-")
}