Skip to content

Commit

Permalink
MaxTitle
Browse files Browse the repository at this point in the history
  • Loading branch information
drgrib committed Jul 20, 2023
1 parent a0b837c commit dc4eb4f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions alfred.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ var Variables = map[string]string{}
// Items specifies the "items" array. It can be accessed and iterated directly. It can also be appended to directly or appended to using the convenience function Add(item).
var Items = []Item{}

// MaxTitle specifies the maximum title length used by ExtendTitleToSubtitle.
var MaxTitle = 45

// Icon specifies the "icon" field of an Item.
type Icon struct {
Type string `json:"type,omitempty"`
Expand Down Expand Up @@ -66,14 +69,14 @@ func Add(item Item) {
Items = append(Items, item)
}

// ExtendTitleToSubtitle extends words of item.Title that cause its string length to exceed maxTitle to item.Subtitle.
func ExtendTitleToSubtitle(item Item, maxTitle int) Item {
if len(item.Title) > maxTitle {
// ExtendTitleToSubtitle extends words of item.Title that cause its string length to exceed MaxTitle to item.Subtitle.
func ExtendTitleToSubtitle(item Item) Item {
if len(item.Title) > MaxTitle {
words := strings.Split(item.Title, " ")
titleLen := len(words[0])
titleWords := []string{words[0]}
i := 1
for ; titleLen+1+len(words[i]) < maxTitle; i++ {
for ; titleLen+1+len(words[i]) < MaxTitle; i++ {
titleWords = append(titleWords, words[i])
titleLen += 1 + len(words[i])
}
Expand Down

0 comments on commit dc4eb4f

Please sign in to comment.