Skip to content

Commit c3ecaed

Browse files
committed
fix
1 parent 7545353 commit c3ecaed

File tree

5 files changed

+8
-16
lines changed

5 files changed

+8
-16
lines changed

templates/repo/view_content.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{{$isTreePathRoot := not .TreeNames}}
22

3+
<div class="repo-view-content-data tw-hidden" data-document-title="{{ctx.RootData.Title}}"></div>
34
{{template "repo/sub_menu" .}}
45
<div class="repo-button-row">
56
<div class="repo-button-row-left">

templates/repo/view_file_tree.tmpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
{{/* TODO: Dynamically move components such as refSelector and createPR here */}}
1111
<div id="view-file-tree" class="tw-overflow-auto tw-h-full is-loading"
1212
data-repo-link="{{.RepoLink}}"
13-
data-repo-name="{{.Repository.Name}}"
1413
data-tree-path="{{$.TreePath}}"
1514
data-current-ref-name-sub-url="{{.RefTypeNameSubURL}}"
1615
></div>

web_src/js/components/ViewFileTree.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const elRoot = useTemplateRef('elRoot');
77
88
const props = defineProps({
99
repoLink: {type: String, required: true},
10-
repoName: {type: String, required: true},
1110
treePath: {type: String, required: true},
1211
currentRefNameSubURL: {type: String, required: true},
1312
});

web_src/js/components/ViewFileTreeStore.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {pathEscapeSegments} from '../utils/url.ts';
44
import {createElementFromHTML} from '../utils/dom.ts';
55
import {html} from '../utils/html.ts';
66

7-
export function createViewFileTreeStore(props: {repoLink: string, repoName: string, treePath: string, currentRefNameSubURL: string}) {
7+
export function createViewFileTreeStore(props: {repoLink: string, treePath: string, currentRefNameSubURL: string}) {
88
const store = reactive({
99
rootFiles: [],
1010
selectedItem: props.treePath,
@@ -25,30 +25,24 @@ export function createViewFileTreeStore(props: {repoLink: string, repoName: stri
2525
},
2626

2727
async loadViewContent(url: string) {
28-
url = url.includes('?') ? url.replace('?', '?only_content=true') : `${url}?only_content=true`;
29-
const response = await GET(url);
30-
document.querySelector('.repo-view-content').innerHTML = await response.text();
28+
const u = new URL(url, window.origin);
29+
u.searchParams.set('only_content', '1');
30+
const response = await GET(u.href);
31+
const elViewContent = document.querySelector('.repo-view-content');
32+
elViewContent.innerHTML = await response.text();
33+
document.title = elViewContent.querySelector('.repo-view-content-data').getAttribute('data-document-title');
3134
},
3235

3336
async navigateTreeView(treePath: string) {
3437
const url = store.buildTreePathWebUrl(treePath);
35-
const title = store.buildTitle(store.selectedItem, treePath);
3638
window.history.pushState({treePath, url}, null, url);
3739
store.selectedItem = treePath;
3840
await store.loadViewContent(url);
39-
document.title = title;
4041
},
4142

4243
buildTreePathWebUrl(treePath: string) {
4344
return `${props.repoLink}/src/${props.currentRefNameSubURL}/${pathEscapeSegments(treePath)}`;
4445
},
45-
46-
buildTitle(oldTreePath: string, treePath: string) {
47-
// the title always starts with "<repoName>/<treePath>"
48-
const oldPrefixLength = props.repoName.length + 1 + oldTreePath.length;
49-
const titleSuffix = document.title.substring(oldPrefixLength);
50-
return `${props.repoName}/${treePath}${titleSuffix}`;
51-
},
5246
});
5347
return store;
5448
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export async function initRepoViewFileTree() {
3131
const fileTree = sidebar.querySelector('#view-file-tree');
3232
createApp(ViewFileTree, {
3333
repoLink: fileTree.getAttribute('data-repo-link'),
34-
repoName: fileTree.getAttribute('data-repo-name'),
3534
treePath: fileTree.getAttribute('data-tree-path'),
3635
currentRefNameSubURL: fileTree.getAttribute('data-current-ref-name-sub-url'),
3736
}).mount(fileTree);

0 commit comments

Comments
 (0)