GitRoot

Craft your forge, Build your project, Grow your community freely
 1// SPDX-FileCopyrightText: 2026 Romain Maneschi <romain@gitroot.dev>
 2//
 3// SPDX-License-Identifier: EUPL-1.2
 4
 5package main
 6
 7import (
 8	"fmt"
 9	"strings"
10)
11
12type rendererList struct {
13	conf Conf
14}
15
16func NewRendererList(conf Conf) rendererList {
17	return rendererList{conf: conf}
18}
19
20func (r rendererList) renderPage(pageBuilder *strings.Builder, lines []CacheLineRelativeLink) {
21	for _, line := range lines {
22		r.makeLink(pageBuilder, line.line, line.relativePath)
23		pageBuilder.WriteString("\n")
24	}
25}
26
27func (r rendererList) makeLink(pageBuilder *strings.Builder, cacheLine CacheLine, path string) {
28	if r.conf.Format == "task" {
29		pageBuilder.WriteString("- [ ] ")
30	} else {
31		pageBuilder.WriteString("- ")
32	}
33
34	fmt.Fprintf(pageBuilder, "[%s](%s)", cacheLine.title, path)
35
36	t := cacheLine.selects
37	for _, a := range t {
38		if a != " " { //special case du to serialization in cache
39			pageBuilder.WriteString(" ")
40			pageBuilder.WriteString(a)
41		}
42	}
43}