MCPcopy Index your code
hub / github.com/syncthing/syncthing / write

Function write

script/copyrights.go:212–250  ·  view source on GitHub ↗
(notices []CopyrightNotice, bs []byte)

Source from the content-addressed store, hash-verified

210}
211
212func write(notices []CopyrightNotice, bs []byte) int {
213 keys := make([]string, 0, len(notices))
214
215 noticeMap := make(map[string]CopyrightNotice, 0)
216
217 for _, n := range notices {
218 if n.Type != TypeKeep && n.Type != TypeNew {
219 continue
220 }
221 if n.Type == TypeNew {
222 fmt.Printf("Adding: %-40s %-55s %s\n", n.Name, n.URL, n.Copyright)
223 }
224 keys = append(keys, n.Name)
225 noticeMap[n.Name] = n
226 }
227
228 slices.Sort(keys)
229
230 indent := " "
231 replacements := []string{}
232 for _, n := range notices {
233 if n.Type != TypeJS {
234 continue
235 }
236 replacements = append(replacements, indent+n.HTML)
237 }
238
239 for _, k := range keys {
240 n := noticeMap[k]
241 line := fmt.Sprintf("%s<li><a href=\"%s\">%s</a>, %s.</li>", indent, n.URL, n.Name, n.Copyright)
242 replacements = append(replacements, line)
243 }
244 replacement := strings.Join(replacements, "\n")
245
246 bs = copyrightRe.ReplaceAll(bs, []byte("id=\"copyright-notices\">\n"+replacement+"\n </ul>"))
247 writeFile(htmlFile, string(bs))
248
249 return len(replacements)
250}
251
252func readAll(path string) []byte {
253 fd, err := os.Open(path)

Callers 1

mainFunction · 0.85

Calls 2

SortMethod · 0.80
writeFileFunction · 0.70

Tested by

no test coverage detected