Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion routers/web/repo/view_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func prepareFileView(ctx *context.Context, entry *git.TreeEntry) {

blob := entry.Blob()

ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+path.Base(ctx.Repo.TreePath), ctx.Repo.RefFullName.ShortName())
ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+ctx.Repo.TreePath, ctx.Repo.RefFullName.ShortName())
ctx.Data["FileIsSymlink"] = entry.IsLink()
ctx.Data["FileTreePath"] = ctx.Repo.TreePath
ctx.Data["RawFileLink"] = ctx.Repo.RepoLink + "/raw/" + ctx.Repo.RefTypeNameSubURL() + "/" + util.PathEscapeSegments(ctx.Repo.TreePath)
Expand Down
3 changes: 1 addition & 2 deletions routers/web/repo/view_home.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"net/http"
"path"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -146,7 +145,7 @@ func prepareToRenderDirectory(ctx *context.Context) {

if ctx.Repo.TreePath != "" {
ctx.Data["HideRepoInfo"] = true
ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+path.Base(ctx.Repo.TreePath), ctx.Repo.RefFullName.ShortName())
ctx.Data["Title"] = ctx.Tr("repo.file.title", ctx.Repo.Repository.Name+"/"+ctx.Repo.TreePath, ctx.Repo.RefFullName.ShortName())
}

subfolder, readmeFile, err := findReadmeFileInEntries(ctx, ctx.Repo.TreePath, entries, true)
Expand Down
1 change: 1 addition & 0 deletions templates/repo/view_file_tree.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{{/* TODO: Dynamically move components such as refSelector and createPR here */}}
<div id="view-file-tree" class="tw-overflow-auto tw-h-full is-loading"
data-repo-link="{{.RepoLink}}"
data-repo-name="{{.Repository.Name}}"
data-tree-path="{{$.TreePath}}"
data-current-ref-name-sub-url="{{.RefTypeNameSubURL}}"
></div>
1 change: 1 addition & 0 deletions web_src/js/components/ViewFileTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const elRoot = useTemplateRef('elRoot');

const props = defineProps({
repoLink: {type: String, required: true},
repoName: {type: String, required: true},
treePath: {type: String, required: true},
currentRefNameSubURL: {type: String, required: true},
});
Expand Down
11 changes: 10 additions & 1 deletion web_src/js/components/ViewFileTreeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {pathEscapeSegments} from '../utils/url.ts';
import {createElementFromHTML} from '../utils/dom.ts';
import {html} from '../utils/html.ts';

export function createViewFileTreeStore(props: {repoLink: string, treePath: string, currentRefNameSubURL: string}) {
export function createViewFileTreeStore(props: {repoLink: string, repoName: string, treePath: string, currentRefNameSubURL: string}) {
const store = reactive({
rootFiles: [],
selectedItem: props.treePath,
Expand Down Expand Up @@ -32,14 +32,23 @@ export function createViewFileTreeStore(props: {repoLink: string, treePath: stri

async navigateTreeView(treePath: string) {
const url = store.buildTreePathWebUrl(treePath);
const title = store.buildTitle(store.selectedItem, treePath);
window.history.pushState({treePath, url}, null, url);
store.selectedItem = treePath;
await store.loadViewContent(url);
document.title = title;
},

buildTreePathWebUrl(treePath: string) {
return `${props.repoLink}/src/${props.currentRefNameSubURL}/${pathEscapeSegments(treePath)}`;
},

buildTitle(oldTreePath: string, treePath: string) {
// the title always starts with "<repoName>/<treePath>"
const oldPrefixLength = props.repoName.length + 1 + oldTreePath.length;
const titleSuffix = document.title.substring(oldPrefixLength);
return `${props.repoName}/${treePath}${titleSuffix}`;
},
});
return store;
}
1 change: 1 addition & 0 deletions web_src/js/features/repo-view-file-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function initRepoViewFileTree() {
const fileTree = sidebar.querySelector('#view-file-tree');
createApp(ViewFileTree, {
repoLink: fileTree.getAttribute('data-repo-link'),
repoName: fileTree.getAttribute('data-repo-name'),
treePath: fileTree.getAttribute('data-tree-path'),
currentRefNameSubURL: fileTree.getAttribute('data-current-ref-name-sub-url'),
}).mount(fileTree);
Expand Down