0.0.971 cdbcd03

html.go RawHistoryFolder

1package render
2
3import (
4	"bytes"
5	"fmt"
6	"html/template"
7	"io/fs"
8	"path"
9
10	"github.com/bnema/gordon/internal/server"
11)
12
13type Renderer struct {
14	Template     *template.Template
15	ParseError   error
16	BuildVersion string
17}
18
19// Render function renders the template with the given data
20func (r *Renderer) Render(data interface{}, a *server.App) (string, error) {
21	if r.ParseError != nil {
22		return "", fmt.Errorf("failed to parse template: %w", r.ParseError)
23
24	}
25	if r.Template == nil {
26		return "", fmt.Errorf("template is nil")
27	}
28	// Type assert data to map[string]interface{} to add BuildVersion
29	dataMap, ok := data.(map[string]interface{})
30	if !ok {
31		return "", fmt.Errorf("data is not a map[string]interface{}")
32	}
33
34	// Automatically add BuildVersion to the data map
35	dataMap["BuildVersion"] = r.BuildVersion
36	buf := new(bytes.Buffer)
37	err := r.Template.Execute(buf, dataMap)
38	if err != nil {
39		return "", fmt.Errorf("failed to execute template: %w", err)
40	}
41
42	return buf.String(), nil
43}
44
45// GetHTMLRenderer function returns a new Renderer instance
46func GetHTMLRenderer(mainPath string, filename string, fs fs.FS, a *server.App, fragmentsPath ...string) (*Renderer, error) {
47	// Full path to the main template
48	fullPath := path.Join(mainPath, filename)
49	// Check if the file exists in the provided fs.FS using fs.Open
50	file, err := fs.Open(fullPath)
51	if err != nil {
52		return nil, fmt.Errorf("failed to open %s: %w", filename, err)
53	}
54	file.Close()
55
56	// Parse the main template
57	tmpl, err := template.New(filename).ParseFS(fs, fullPath)
58	if err != nil {
59		return nil, fmt.Errorf("failed to parse %s: %w", filename, err)
60	}
61
62	// If a fragments path is provided, parse the fragment templates
63	if len(fragmentsPath) > 0 && fragmentsPath[0] != "" {
64		fragmentsGlob := path.Join(fragmentsPath[0], "*.gohtml")
65		_, err = tmpl.ParseFS(fs, fragmentsGlob)
66		if err != nil {
67			return nil, fmt.Errorf("failed to parse fragments: %w", err)
68		}
69	}
70
71	// Return the Renderer instance
72	return &Renderer{
73		Template:     tmpl,
74		BuildVersion: a.Config.Build.BuildVersion,
75	}, nil
76}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close