Skip to content

Commit 3b41bea

Browse files
committed
Split the original repo/home.tmpl into two templates: home and view.
1 parent 9403372 commit 3b41bea

File tree

8 files changed

+55
-19
lines changed

8 files changed

+55
-19
lines changed

routers/web/repo/blame.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ func RefBlame(ctx *context.Context) {
9595

9696
var tplName templates.TplName
9797
if ctx.FormBool("only_content") {
98-
tplName = tplRepoHomeContent
98+
tplName = tplRepoViewContent
9999
} else {
100-
tplName = tplRepoHome
100+
tplName = tplRepoView
101101
}
102102

103103
if fileSize >= setting.UI.MaxDisplayFileSize {

routers/web/repo/view.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ import (
4949
const (
5050
tplRepoEMPTY templates.TplName = "repo/empty"
5151
tplRepoHome templates.TplName = "repo/home"
52-
tplRepoHomeContent templates.TplName = "repo/home_content"
52+
tplRepoView templates.TplName = "repo/view"
53+
tplRepoViewContent templates.TplName = "repo/view_content"
5354
tplRepoViewList templates.TplName = "repo/view_list"
5455
tplWatchers templates.TplName = "repo/watchers"
5556
tplForks templates.TplName = "repo/forks"

routers/web/repo/view_home.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ func Home(ctx *context.Context) {
430430
}
431431

432432
if ctx.FormBool("only_content") {
433-
ctx.HTML(http.StatusOK, tplRepoHomeContent)
433+
ctx.HTML(http.StatusOK, tplRepoViewContent)
434+
} else if len(treeNames) != 0 {
435+
ctx.HTML(http.StatusOK, tplRepoView)
434436
} else {
435437
ctx.HTML(http.StatusOK, tplRepoHome)
436438
}

templates/repo/home.tmpl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717

1818
{{template "repo/code/recently_pushed_new_branches" .}}
1919

20-
<div class="{{Iif $showSidebar "repo-grid-filelist-sidebar" (Iif .RepoPreferences.ShowFileViewTreeSidebar "repo-grid-tree-sidebar" "repo-grid-filelist-only")}}">
21-
{{if .TreeNames}}
22-
<div class="repo-view-file-tree-sidebar not-mobile {{if not .RepoPreferences.ShowFileViewTreeSidebar}}tw-hidden{{end}}" {{if .IsSigned}} data-is-signed {{end}}>{{template "repo/view_file_tree_sidebar" .}}</div>
23-
{{end}}
24-
20+
<div class="{{Iif $showSidebar "repo-grid-filelist-sidebar" "repo-grid-filelist-only"}}">
2521
<div class="repo-home-filelist">
26-
{{template "repo/home_content" .}}
22+
{{template "repo/view_content" .}}
2723
</div>
2824

2925
{{if $showSidebar}}

templates/repo/view.tmpl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{{template "base/head" .}}
2+
<div role="main" aria-label="{{.Title}}" class="page-content repository file list {{if .IsBlame}}blame{{end}}">
3+
{{template "repo/header" .}}
4+
<div class="ui container {{if or .TreeNames .IsBlame}}fluid padded{{end}}">
5+
{{template "base/alert" .}}
6+
7+
{{if .Repository.IsArchived}}
8+
<div class="ui warning message tw-text-center">
9+
{{if .Repository.ArchivedUnix.IsZero}}
10+
{{ctx.Locale.Tr "repo.archive.title"}}
11+
{{else}}
12+
{{ctx.Locale.Tr "repo.archive.title_date" (DateUtils.AbsoluteLong .Repository.ArchivedUnix)}}
13+
{{end}}
14+
</div>
15+
{{end}}
16+
17+
{{template "repo/code/recently_pushed_new_branches" .}}
18+
19+
<div class="{{Iif .RepoPreferences.ShowFileViewTreeSidebar "repo-view-with-sidebar" "repo-view-content-only"}}">
20+
<div class="repo-view-file-tree-sidebar not-mobile {{if not .RepoPreferences.ShowFileViewTreeSidebar}}tw-hidden{{end}}" {{if .IsSigned}} data-is-signed {{end}}>{{template "repo/view_file_tree_sidebar" .}}</div>
21+
<div class="repo-view-content">
22+
{{template "repo/view_content" .}}
23+
</div>
24+
</div>
25+
</div>
26+
</div>
27+
{{template "base/footer" .}}
File renamed without changes.

web_src/css/repo/home.css

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,19 @@
4949
}
5050
}
5151

52-
.repo-grid-tree-sidebar {
52+
.repo-view-with-sidebar {
5353
display: grid;
5454
grid-template-columns: 300px auto;
5555
grid-template-rows: auto auto 1fr;
5656
}
5757

58-
.repo-grid-tree-sidebar .repo-home-filelist {
58+
.repo-view-content {
59+
min-width: 0;
60+
grid-column: 1;
61+
grid-row: 1 / 4;
62+
}
63+
64+
.repo-view-with-sidebar .repo-view-content {
5965
min-width: 0;
6066
grid-column: 2;
6167
grid-row: 1 / 4;
@@ -66,7 +72,7 @@
6672
aspect-ratio: 5.415; /* the size is about 790 x 145 */
6773
}
6874

69-
.repo-grid-tree-sidebar .repo-view-file-tree-sidebar {
75+
.repo-view-with-sidebar .repo-view-file-tree-sidebar {
7076
display: flex;
7177
flex-direction: column;
7278
gap: 8px;
@@ -77,15 +83,19 @@
7783
z-index: 8;
7884
}
7985

80-
.repo-grid-tree-sidebar .repo-button-row {
86+
.repo-view-with-sidebar .repo-button-row {
8187
margin-top: 0 !important;
8288
}
8389

8490
@media (max-width: 767.98px) {
85-
.repo-grid-tree-sidebar {
91+
.repo-view-with-sidebar {
8692
grid-template-columns: auto;
8793
grid-template-rows: auto auto auto;
8894
}
95+
.repo-view-content {
96+
grid-column: 1;
97+
grid-row: 2;
98+
}
8999
}
90100

91101
.language-stats {

web_src/js/features/repo-view-file-tree-sidebar.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const {appSubUrl} = window.config;
99
async function toggleSidebar(sidebarEl: HTMLElement, shouldShow: boolean) {
1010
const showBtnEl = sidebarEl.parentElement.querySelector('.show-tree-sidebar-button');
1111
const containerClassList = sidebarEl.parentElement.classList;
12-
containerClassList.toggle('repo-grid-tree-sidebar', shouldShow);
13-
containerClassList.toggle('repo-grid-filelist-only', !shouldShow);
12+
containerClassList.toggle('repo-view-with-sidebar', shouldShow);
13+
containerClassList.toggle('repo-view-content-only', !shouldShow);
1414
toggleElem(sidebarEl, shouldShow);
1515
toggleElem(showBtnEl, !shouldShow);
1616

@@ -49,7 +49,7 @@ function childrenLoader(sidebarEl: HTMLElement) {
4949
async function loadContent(sidebarEl: HTMLElement) {
5050
// load content by path (content based on home_content.tmpl)
5151
const response = await GET(`${window.location.href}?only_content=true`);
52-
const contentEl = sidebarEl.parentElement.querySelector('.repo-home-filelist');
52+
const contentEl = sidebarEl.parentElement.querySelector('.repo-view-content');
5353
contentEl.innerHTML = await response.text();
5454
reloadContentScript(sidebarEl, contentEl);
5555
}
@@ -67,7 +67,7 @@ export async function initViewFileTreeSidebar() {
6767
sidebarEl.querySelector('.hide-tree-sidebar-button').addEventListener('click', () => {
6868
toggleSidebar(sidebarEl, false);
6969
});
70-
sidebarEl.parentElement.querySelector('.repo-home-filelist .show-tree-sidebar-button').addEventListener('click', () => {
70+
sidebarEl.parentElement.querySelector('.repo-view-content .show-tree-sidebar-button').addEventListener('click', () => {
7171
toggleSidebar(sidebarEl, true);
7272
});
7373

0 commit comments

Comments
 (0)