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

Configure Feed

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

Get locales directly from context like the other code; add translations for subtitle

+25 -33
+21 -13
modules/markup/html.go
··· 5 5 6 6 import ( 7 7 "bytes" 8 + "html/template" 8 9 "io" 9 10 "net/url" 10 11 "path" ··· 1065 1066 if ctx.Metas == nil { 1066 1067 return 1067 1068 } 1068 - if DefaultProcessorHelper.GetRepoFileContent == nil || DefaultProcessorHelper.GetLocale == nil { 1069 + if DefaultProcessorHelper.GetRepoFileContent == nil { 1069 1070 return 1070 1071 } 1071 1072 ··· 1119 1120 lineSpecs := strings.Split(hash, "-") 1120 1121 lineCount := len(fileContent) 1121 1122 1122 - var subTitle string 1123 + commitLinkBuffer := new(bytes.Buffer) 1124 + html.Render(commitLinkBuffer, createLink(node.Data[m[0]:m[5]], commitSha[0:7], "text black")) 1125 + 1126 + var subTitle template.HTML 1123 1127 var lineOffset int 1124 1128 1129 + locale, ok := ctx.Ctx.Value(translation.ContextKey).(translation.Locale) 1130 + if !ok { 1131 + locale = translation.NewLocale("en-US") 1132 + } 1133 + 1125 1134 if len(lineSpecs) == 1 { 1126 1135 line, _ := strconv.Atoi(strings.TrimPrefix(lineSpecs[0], "L")) 1127 1136 if line < 1 || line > lineCount { ··· 1129 1138 } 1130 1139 1131 1140 fileContent = fileContent[line-1 : line] 1132 - subTitle = "Line " + strconv.Itoa(line) 1141 + subTitle = locale.Tr( 1142 + "markup.filepreview.line", line, 1143 + template.HTML(commitLinkBuffer.String()), 1144 + ) 1133 1145 1134 1146 lineOffset = line - 1 1135 1147 } else { ··· 1141 1153 } 1142 1154 1143 1155 fileContent = fileContent[startLine-1 : endLine] 1144 - subTitle = "Lines " + strconv.Itoa(startLine) + " to " + strconv.Itoa(endLine) 1156 + subTitle = locale.Tr( 1157 + "markup.filepreview.lines", startLine, endLine, 1158 + template.HTML(commitLinkBuffer.String()), 1159 + ) 1145 1160 1146 1161 lineOffset = startLine - 1 1147 1162 } ··· 1154 1169 tbody := &html.Node{ 1155 1170 Type: html.ElementNode, 1156 1171 Data: atom.Tbody.String(), 1157 - } 1158 - 1159 - locale, err := DefaultProcessorHelper.GetLocale(ctx.Ctx) 1160 - if err != nil { 1161 - log.Error("Unable to get locale. Error: %v", err) 1162 - return 1163 1172 } 1164 1173 1165 1174 status := &charset.EscapeStatus{} ··· 1286 1295 Attr: []html.Attribute{{Key: "class", Val: "text small grey"}}, 1287 1296 } 1288 1297 psubtitle.AppendChild(&html.Node{ 1289 - Type: html.TextNode, 1290 - Data: subTitle + " in ", 1298 + Type: html.RawNode, 1299 + Data: string(subTitle), 1291 1300 }) 1292 - psubtitle.AppendChild(createLink(urlFull[m[0]:m[5]], commitSha[0:7], "text black")) 1293 1301 header.AppendChild(psubtitle) 1294 1302 1295 1303 preview := &html.Node{
-4
modules/markup/html_test.go
··· 19 19 "code.gitea.io/gitea/modules/markup" 20 20 "code.gitea.io/gitea/modules/markup/markdown" 21 21 "code.gitea.io/gitea/modules/setting" 22 - "code.gitea.io/gitea/modules/translation" 23 22 "code.gitea.io/gitea/modules/util" 24 23 25 24 "github.com/stretchr/testify/assert" ··· 683 682 GetRepoFileContent: func(ctx context.Context, ownerName, repoName, commitSha, filePath string) ([]template.HTML, error) { 684 683 buf := []byte("A\nB\nC\nD\n") 685 684 return highlight.PlainText(buf), nil 686 - }, 687 - GetLocale: func(ctx context.Context) (translation.Locale, error) { 688 - return translation.NewLocale("en-US"), nil 689 685 }, 690 686 }) 691 687
-2
modules/markup/renderer.go
··· 17 17 18 18 "code.gitea.io/gitea/modules/git" 19 19 "code.gitea.io/gitea/modules/setting" 20 - "code.gitea.io/gitea/modules/translation" 21 20 "code.gitea.io/gitea/modules/util" 22 21 23 22 "github.com/yuin/goldmark/ast" ··· 34 33 type ProcessorHelper struct { 35 34 IsUsernameMentionable func(ctx context.Context, username string) bool 36 35 GetRepoFileContent func(ctx context.Context, ownerName, repoName, commitSha, filePath string) ([]template.HTML, error) 37 - GetLocale func(ctx context.Context) (translation.Locale, error) 38 36 39 37 ElementDir string // the direction of the elements, eg: "ltr", "rtl", "auto", default to no direction attribute 40 38 }
+4
options/locale/locale_en-US.ini
··· 3707 3707 executable_file = Executable file 3708 3708 symbolic_link = Symbolic link 3709 3709 submodule = Submodule 3710 + 3711 + [markup] 3712 + filepreview.line = Line %[1]d in %[3]s 3713 + filepreview.lines = Lines %[1]d to %[2]d in %[3]s
-14
services/markup/processorhelper.go
··· 17 17 "code.gitea.io/gitea/modules/highlight" 18 18 "code.gitea.io/gitea/modules/log" 19 19 "code.gitea.io/gitea/modules/markup" 20 - "code.gitea.io/gitea/modules/translation" 21 20 gitea_context "code.gitea.io/gitea/services/context" 22 21 file_service "code.gitea.io/gitea/services/repository/files" 23 22 ) ··· 99 98 } 100 99 101 100 return fileContent, nil 102 - }, 103 - GetLocale: func(ctx context.Context) (translation.Locale, error) { 104 - giteaCtx, ok := ctx.(*gitea_context.Context) 105 - if ok { 106 - return giteaCtx.Locale, nil 107 - } 108 - 109 - giteaBaseCtx, ok := ctx.(*gitea_context.Base) 110 - if ok { 111 - return giteaBaseCtx.Locale, nil 112 - } 113 - 114 - return nil, fmt.Errorf("could not retrieve locale from context") 115 101 }, 116 102 } 117 103 }