all repos

mugit @ 9d3f4dd

馃惍 git server that your cow will love
2 files changed, 43 insertions(+), 11 deletions(-)
ui: add breadcrumbs to file content view
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-03-05 20:58:57 +0200
Authored at: 2026-03-05 20:57:45 +0200
Change ID: olmzpxznknwssqnwutykuxnzlwtnyopr
Parent: 99af93d
M internal/handlers/repo.go
路路路
        158
        158
         }

      
        159
        159
         

      
        160
        160
         type RepoFile struct {

      
        161
        
        -	Ref       string

      
        162
        
        -	Desc      string

      
        163
        
        -	LineCount []int

      
        164
        
        -	Path      string

      
        165
        
        -	IsImage   bool

      
        166
        
        -	IsBinary  bool

      
        167
        
        -	Content   string

      
        168
        
        -	Mime      string

      
        169
        
        -	Size      int64

      
        
        161
        +	Ref         string

      
        
        162
        +	Desc        string

      
        
        163
        +	LineCount   []int

      
        
        164
        +	Breadcrumbs []Breadcrumb

      
        
        165
        +	Path        string

      
        
        166
        +	IsImage     bool

      
        
        167
        +	IsBinary    bool

      
        
        168
        +	Content     string

      
        
        169
        +	Mime        string

      
        
        170
        +	Size        int64

      
        170
        171
         }

      
        171
        172
         

      
        172
        173
         func (h *handlers) fileContentsHandler(w http.ResponseWriter, r *http.Request) {

      路路路
        228
        229
         			lines[i] = i + 1

      
        229
        230
         		}

      
        230
        231
         		p.Content = contentStr

      
        231
        
        -		p.LineCount = lines

      
        
        232
        +		p.LineCount = lines // TODO: replace with strings.Count(, "\n")

      
        
        233
        +		p.Breadcrumbs = Breadcrumbs(treePath)

      
        232
        234
         	}

      
        233
        235
         

      
        234
        236
         	h.templ(w, "repo_file", h.pageData(repo, p))

      路路路
        518
        520
         		},

      
        519
        521
         	}

      
        520
        522
         }

      
        
        523
        +

      
        
        524
        +type Breadcrumb struct {

      
        
        525
        +	Name   string

      
        
        526
        +	Path   string

      
        
        527
        +	IsLast bool

      
        
        528
        +}

      
        
        529
        +

      
        
        530
        +func Breadcrumbs(path string) []Breadcrumb {

      
        
        531
        +	if path == "" {

      
        
        532
        +		return nil

      
        
        533
        +	}

      
        
        534
        +	parts := strings.Split(path, "/")

      
        
        535
        +	crumbs := make([]Breadcrumb, len(parts))

      
        
        536
        +	for i, part := range parts {

      
        
        537
        +		crumbs[i] = Breadcrumb{

      
        
        538
        +			Name:   part,

      
        
        539
        +			Path:   strings.Join(parts[:i+1], "/"),

      
        
        540
        +			IsLast: i == len(parts)-1,

      
        
        541
        +		}

      
        
        542
        +	}

      
        
        543
        +	return crumbs

      
        
        544
        +}

      
M web/templates/repo_file.html
路路路
        7
        7
           <body>

      
        8
        8
             {{ template "repo_header" . }}

      
        9
        9
             <main>

      
        10
        
        -      <p>{{ .P.Path }} (<a class="muted" href="?raw=true">view raw</a>)</p>

      
        
        10
        +      <p>

      
        
        11
        +        <a class="link" href="/{{ .RepoName }}/tree/{{ .P.Ref }}">{{ .RepoName }}</a>

      
        
        12
        +        {{- range .P.Breadcrumbs  -}}

      
        
        13
        +        <span class="mode">/</span>

      
        
        14
        +        {{- if .IsLast -}}{{- .Name -}}

      
        
        15
        +        {{- else -}}<a class="link" href="{{ $.RepoName }}/tree/{{ $.P.Ref }}/{{ $.P.Path }}">{{ .Name }}</a>{{- end -}}

      
        
        16
        +        {{- end -}}

      
        
        17
        +        (<a class="muted" href="?raw=true">view raw</a>)

      
        
        18
        +      </p>

      
        11
        19
               <div class="file-wrapper">

      
        12
        20
                 {{ if .P.IsImage }}

      
        13
        21
                 <div class="image-viewer">