loading up the forgejo repo on tangled to test page performance
fork

Configure Feed

Select the types of activity you want to include in your feed.

templates: HasPrefix support for template.HTML

Refactor locale&string&template related code has .Title be
template.HTML and "Improve HTML title on repositories" needs to check
the prefix with StringUtils.HasPrefix

+29 -2
+9 -2
modules/templates/util_string.go
··· 4 4 package templates 5 5 6 6 import ( 7 + "html/template" 7 8 "strings" 8 9 9 10 "code.gitea.io/gitea/modules/base" ··· 17 18 return &stringUtils 18 19 } 19 20 20 - func (su *StringUtils) HasPrefix(s, prefix string) bool { 21 - return strings.HasPrefix(s, prefix) 21 + func (su *StringUtils) HasPrefix(s any, prefix string) bool { 22 + switch v := s.(type) { 23 + case string: 24 + return strings.HasPrefix(v, prefix) 25 + case template.HTML: 26 + return strings.HasPrefix(string(v), prefix) 27 + } 28 + return false 22 29 } 23 30 24 31 func (su *StringUtils) Contains(s, substr string) bool {
+20
modules/templates/util_string_test.go
··· 1 + // Copyright Earl Warren <contact@earl-warren.org> 2 + // SPDX-License-Identifier: MIT 3 + 4 + package templates 5 + 6 + import ( 7 + "html/template" 8 + "testing" 9 + 10 + "github.com/stretchr/testify/assert" 11 + ) 12 + 13 + func Test_StringUtils_HasPrefix(t *testing.T) { 14 + su := &StringUtils{} 15 + assert.True(t, su.HasPrefix("ABC", "A")) 16 + assert.False(t, su.HasPrefix("ABC", "B")) 17 + assert.True(t, su.HasPrefix(template.HTML("ABC"), "A")) 18 + assert.False(t, su.HasPrefix(template.HTML("ABC"), "B")) 19 + assert.False(t, su.HasPrefix(123, "B")) 20 + }