Slugify: Replace gosimple/slug with a simple function (#59517)

This commit is contained in:
Ryan McKinley
2022-11-30 11:12:56 -05:00
committed by GitHub
parent 000de83eb4
commit 5b71a16acf
13 changed files with 443 additions and 56 deletions
@@ -1,13 +1,10 @@
package ualert
import (
"encoding/base64"
"strings"
"time"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/gosimple/slug"
"github.com/grafana/grafana/pkg/infra/slugify"
)
type dashboard struct {
@@ -45,22 +42,7 @@ func (d *dashboard) setVersion(version int) {
// UpdateSlug updates the slug
func (d *dashboard) updateSlug() {
title := d.Data.Get("title").MustString()
d.Slug = slugifyTitle(title)
}
func slugifyTitle(title string) string {
s := slug.Make(strings.ToLower(title))
if s == "" {
// If the dashboard name is only characters outside of the
// sluggable characters, the slug creation will return an
// empty string which will mess up URLs. This failsafe picks
// that up and creates the slug as a base64 identifier instead.
s = base64.RawURLEncoding.EncodeToString([]byte(title))
if slug.MaxLength != 0 && len(s) > slug.MaxLength {
s = s[:slug.MaxLength]
}
}
return s
d.Slug = slugify.Slugify(title)
}
func newDashboardFromJson(data *simplejson.Json) *dashboard {