forked from forgejo/forgejo
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
This commit is contained in:
parent
4af0944b26
commit
c021a5b919
2 changed files with 29 additions and 2 deletions
|
@ -4,6 +4,7 @@
|
|||
package templates
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
|
@ -17,8 +18,14 @@ func NewStringUtils() *StringUtils {
|
|||
return &stringUtils
|
||||
}
|
||||
|
||||
func (su *StringUtils) HasPrefix(s, prefix string) bool {
|
||||
return strings.HasPrefix(s, prefix)
|
||||
func (su *StringUtils) HasPrefix(s any, prefix string) bool {
|
||||
switch v := s.(type) {
|
||||
case string:
|
||||
return strings.HasPrefix(v, prefix)
|
||||
case template.HTML:
|
||||
return strings.HasPrefix(string(v), prefix)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (su *StringUtils) Contains(s, substr string) bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue