Slugify: Replace gosimple/slug with a simple function (#59517)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user