Commit 4693364

Anton Medvedev <anton@medv.io>
2025-12-07 19:12:04
Replace `CurrentRef` with `CurrentRefDir` in layout parameters
1 parent 59608fd
pkg/templates/layout.gohtml
@@ -268,7 +268,7 @@
 <div class="menu">
     <a href="{{ .RootHref }}index.html" class="project-name">{{ .Name }}</a>
     <div class="menu-item {{ if eq .Selected "code" }}selected{{ end }}">
-        <a href="{{ .RootHref }}blob/{{ .CurrentRef }}/index.html">
+        <a href="{{ .RootHref }}blob/{{ .CurrentRefDir }}/index.html">
             <svg aria-hidden="true" width="16" height="16">
                 <use xlink:href="#code"></use>
             </svg>
@@ -292,7 +292,7 @@
         </a>
     </div>
     <div class="menu-item {{ if eq .Selected "commits" }}selected{{ end }}">
-        <a href="{{ .RootHref }}commits/{{ .CurrentRef }}/index.html">
+        <a href="{{ .RootHref }}commits/{{ .CurrentRefDir }}/index.html">
             <svg aria-hidden="true" focusable="false" width="16" height="16">
                 <use xlink:href="#commit"></use>
             </svg>
pkg/templates/templates.go
@@ -66,13 +66,13 @@ var previewContent string
 var PreviewTemplate = Must(New("preview").Parse(previewContent))
 
 type LayoutParams struct {
-	Title       string
-	Name        string
-	Dark        bool
-	CSSMarkdown CSS
-	RootHref    string
-	CurrentRef  git.Ref
-	Selected    string
+	Title         string
+	Name          string
+	Dark          bool
+	CSSMarkdown   CSS
+	RootHref      string
+	CurrentRefDir string
+	Selected      string
 }
 
 type HeaderParams struct {
blob.go
@@ -134,13 +134,13 @@ func generateBlobs(files []git.Blob, params Params) error {
 
 						err = templates.MarkdownTemplate.ExecuteTemplate(f, "layout.gohtml", templates.MarkdownParams{
 							LayoutParams: templates.LayoutParams{
-								Title:       fmt.Sprintf("%s/%s at %s", params.Name, blob.Path, params.Ref),
-								Dark:        params.Dark,
-								CSSMarkdown: cssMarkdown(params.Dark),
-								Name:        params.Name,
-								RootHref:    rootHref,
-								CurrentRef:  params.Ref,
-								Selected:    "code",
+								Title:         fmt.Sprintf("%s/%s at %s", params.Name, blob.Path, params.Ref),
+								Dark:          params.Dark,
+								CSSMarkdown:   cssMarkdown(params.Dark),
+								Name:          params.Name,
+								RootHref:      rootHref,
+								CurrentRefDir: params.Ref.DirName(),
+								Selected:      "code",
 							},
 							HeaderParams: templates.HeaderParams{
 								Ref:         params.Ref,
@@ -193,12 +193,12 @@ func generateBlobs(files []git.Blob, params Params) error {
 
 						err = templates.BlobTemplate.ExecuteTemplate(f, "layout.gohtml", templates.BlobParams{
 							LayoutParams: templates.LayoutParams{
-								Title:      fmt.Sprintf("%s/%s at %s", params.Name, blob.Path, params.Ref),
-								Dark:       params.Dark,
-								Name:       params.Name,
-								RootHref:   rootHref,
-								CurrentRef: params.Ref,
-								Selected:   "code",
+								Title:         fmt.Sprintf("%s/%s at %s", params.Name, blob.Path, params.Ref),
+								Dark:          params.Dark,
+								Name:          params.Name,
+								RootHref:      rootHref,
+								CurrentRefDir: params.Ref.DirName(),
+								Selected:      "code",
 							},
 							HeaderParams: templates.HeaderParams{
 								Ref:         params.Ref,
branches.go
@@ -48,12 +48,12 @@ func generateBranches(branches []git.Ref, defaultBranch string, params Params) e
 
 	err = templates.BranchesTemplate.ExecuteTemplate(f, "layout.gohtml", templates.BranchesParams{
 		LayoutParams: templates.LayoutParams{
-			Title:      fmt.Sprintf("Branches %s %s", dot, params.Name),
-			Name:       params.Name,
-			Dark:       params.Dark,
-			RootHref:   rootHref,
-			CurrentRef: params.DefaultRef,
-			Selected:   "branches",
+			Title:         fmt.Sprintf("Branches %s %s", dot, params.Name),
+			Name:          params.Name,
+			Dark:          params.Dark,
+			RootHref:      rootHref,
+			CurrentRefDir: params.DefaultRef.DirName(),
+			Selected:      "branches",
 		},
 		Branches: entries,
 	})
commit.go
@@ -236,12 +236,12 @@ func generateCommitPage(commit git.Commit, params Params) error {
 
 	err = templates.CommitTemplate.ExecuteTemplate(f, "layout.gohtml", templates.CommitParams{
 		LayoutParams: templates.LayoutParams{
-			Title:      fmt.Sprintf("%s %s %s@%s", commit.Subject, dot, params.Name, commit.ShortHash),
-			Name:       params.Name,
-			Dark:       params.Dark,
-			RootHref:   rootHref,
-			CurrentRef: currentRef,
-			Selected:   "commits",
+			Title:         fmt.Sprintf("%s %s %s@%s", commit.Subject, dot, params.Name, commit.ShortHash),
+			Name:          params.Name,
+			Dark:          params.Dark,
+			RootHref:      rootHref,
+			CurrentRefDir: currentRef.DirName(),
+			Selected:      "commits",
 		},
 		Commit:    commit,
 		DiffCSS:   template.CSS(cssBuf.String()),
commits_list.go
@@ -62,12 +62,12 @@ func generateLogForBranch(allCommits []git.Commit, params Params) error {
 
 		err = templates.CommitsListTemplate.ExecuteTemplate(f, "layout.gohtml", templates.CommitsListParams{
 			LayoutParams: templates.LayoutParams{
-				Title:      fmt.Sprintf("Commits %s %s", dot, params.Name),
-				Name:       params.Name,
-				Dark:       params.Dark,
-				RootHref:   rootHref,
-				CurrentRef: params.Ref,
-				Selected:   "commits",
+				Title:         fmt.Sprintf("Commits %s %s", dot, params.Name),
+				Name:          params.Name,
+				Dark:          params.Dark,
+				RootHref:      rootHref,
+				CurrentRefDir: params.Ref.DirName(),
+				Selected:      "commits",
 			},
 			HeaderParams: templates.HeaderParams{
 				Header: "Commits",
index.go
@@ -100,13 +100,13 @@ func generateIndex(files []git.Blob, params Params) error {
 
 	err = templates.ListTemplate.ExecuteTemplate(f, "layout.gohtml", templates.ListParams{
 		LayoutParams: templates.LayoutParams{
-			Title:       title,
-			Name:        params.Name,
-			Dark:        params.Dark,
-			CSSMarkdown: cssMarkdown(params.Dark),
-			RootHref:    rootHref,
-			CurrentRef:  params.Ref,
-			Selected:    "code",
+			Title:         title,
+			Name:          params.Name,
+			Dark:          params.Dark,
+			CSSMarkdown:   cssMarkdown(params.Dark),
+			RootHref:      rootHref,
+			CurrentRefDir: params.Ref.DirName(),
+			Selected:      "code",
 		},
 		HeaderParams: templates.HeaderParams{
 			Ref:         params.Ref,
list.go
@@ -183,13 +183,13 @@ func generateLists(files []git.Blob, params Params) error {
 
 					err = templates.ListTemplate.ExecuteTemplate(f, "layout.gohtml", templates.ListParams{
 						LayoutParams: templates.LayoutParams{
-							Title:       title,
-							Name:        params.Name,
-							Dark:        params.Dark,
-							CSSMarkdown: CSSMarkdown,
-							RootHref:    rootHref,
-							CurrentRef:  params.Ref,
-							Selected:    "code",
+							Title:         title,
+							Name:          params.Name,
+							Dark:          params.Dark,
+							CSSMarkdown:   CSSMarkdown,
+							RootHref:      rootHref,
+							CurrentRefDir: params.Ref.DirName(),
+							Selected:      "code",
 						},
 						HeaderParams: templates.HeaderParams{
 							Ref:         params.Ref,
tags.go
@@ -25,12 +25,12 @@ func generateTags(entries []git.Tag, params Params) error {
 
 	return templates.TagsTemplate.ExecuteTemplate(f, "layout.gohtml", templates.TagsParams{
 		LayoutParams: templates.LayoutParams{
-			Title:      fmt.Sprintf("Tags %s %s", dot, params.Name),
-			Name:       params.Name,
-			Dark:       params.Dark,
-			RootHref:   rootHref,
-			CurrentRef: params.DefaultRef,
-			Selected:   "tags",
+			Title:         fmt.Sprintf("Tags %s %s", dot, params.Name),
+			Name:          params.Name,
+			Dark:          params.Dark,
+			RootHref:      rootHref,
+			CurrentRefDir: params.DefaultRef.DirName(),
+			Selected:      "tags",
 		},
 		Tags: entries,
 	})