From c3ecaed9541cc5fa496f5409e7119573dbdcea5f Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 29 Oct 2025 20:09:49 +0800 Subject: [PATCH] fix --- templates/repo/view_content.tmpl | 1 + templates/repo/view_file_tree.tmpl | 1 - web_src/js/components/ViewFileTree.vue | 1 - web_src/js/components/ViewFileTreeStore.ts | 20 +++++++------------- web_src/js/features/repo-view-file-tree.ts | 1 - 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/templates/repo/view_content.tmpl b/templates/repo/view_content.tmpl index 3ba04a9974..f1cc811847 100644 --- a/templates/repo/view_content.tmpl +++ b/templates/repo/view_content.tmpl @@ -1,5 +1,6 @@ {{$isTreePathRoot := not .TreeNames}} +
{{template "repo/sub_menu" .}}
diff --git a/templates/repo/view_file_tree.tmpl b/templates/repo/view_file_tree.tmpl index 1e737d09cd..8aed05f346 100644 --- a/templates/repo/view_file_tree.tmpl +++ b/templates/repo/view_file_tree.tmpl @@ -10,7 +10,6 @@ {{/* TODO: Dynamically move components such as refSelector and createPR here */}}
diff --git a/web_src/js/components/ViewFileTree.vue b/web_src/js/components/ViewFileTree.vue index 1bd52d7435..1f90f92586 100644 --- a/web_src/js/components/ViewFileTree.vue +++ b/web_src/js/components/ViewFileTree.vue @@ -7,7 +7,6 @@ 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}, }); diff --git a/web_src/js/components/ViewFileTreeStore.ts b/web_src/js/components/ViewFileTreeStore.ts index 63b585c743..2e78eb8b8b 100644 --- a/web_src/js/components/ViewFileTreeStore.ts +++ b/web_src/js/components/ViewFileTreeStore.ts @@ -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, repoName: string, treePath: string, currentRefNameSubURL: string}) { +export function createViewFileTreeStore(props: {repoLink: string, treePath: string, currentRefNameSubURL: string}) { const store = reactive({ rootFiles: [], selectedItem: props.treePath, @@ -25,30 +25,24 @@ export function createViewFileTreeStore(props: {repoLink: string, repoName: stri }, async loadViewContent(url: string) { - url = url.includes('?') ? url.replace('?', '?only_content=true') : `${url}?only_content=true`; - const response = await GET(url); - document.querySelector('.repo-view-content').innerHTML = await response.text(); + const u = new URL(url, window.origin); + u.searchParams.set('only_content', '1'); + const response = await GET(u.href); + const elViewContent = document.querySelector('.repo-view-content'); + elViewContent.innerHTML = await response.text(); + document.title = elViewContent.querySelector('.repo-view-content-data').getAttribute('data-document-title'); }, 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 "/" - const oldPrefixLength = props.repoName.length + 1 + oldTreePath.length; - const titleSuffix = document.title.substring(oldPrefixLength); - return `${props.repoName}/${treePath}${titleSuffix}`; - }, }); return store; } diff --git a/web_src/js/features/repo-view-file-tree.ts b/web_src/js/features/repo-view-file-tree.ts index 785ec35a5a..f52b64cc51 100644 --- a/web_src/js/features/repo-view-file-tree.ts +++ b/web_src/js/features/repo-view-file-tree.ts @@ -31,7 +31,6 @@ 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);