0.1.9 85724f1

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

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