mirror of
https://github.com/go-gitea/gitea.git
synced 2025-11-05 21:16:11 +01:00
fix
This commit is contained in:
parent
754535318c
commit
c3ecaed954
@ -1,5 +1,6 @@
|
|||||||
{{$isTreePathRoot := not .TreeNames}}
|
{{$isTreePathRoot := not .TreeNames}}
|
||||||
|
|
||||||
|
<div class="repo-view-content-data tw-hidden" data-document-title="{{ctx.RootData.Title}}"></div>
|
||||||
{{template "repo/sub_menu" .}}
|
{{template "repo/sub_menu" .}}
|
||||||
<div class="repo-button-row">
|
<div class="repo-button-row">
|
||||||
<div class="repo-button-row-left">
|
<div class="repo-button-row-left">
|
||||||
|
|||||||
@ -10,7 +10,6 @@
|
|||||||
{{/* TODO: Dynamically move components such as refSelector and createPR here */}}
|
{{/* TODO: Dynamically move components such as refSelector and createPR here */}}
|
||||||
<div id="view-file-tree" class="tw-overflow-auto tw-h-full is-loading"
|
<div id="view-file-tree" class="tw-overflow-auto tw-h-full is-loading"
|
||||||
data-repo-link="{{.RepoLink}}"
|
data-repo-link="{{.RepoLink}}"
|
||||||
data-repo-name="{{.Repository.Name}}"
|
|
||||||
data-tree-path="{{$.TreePath}}"
|
data-tree-path="{{$.TreePath}}"
|
||||||
data-current-ref-name-sub-url="{{.RefTypeNameSubURL}}"
|
data-current-ref-name-sub-url="{{.RefTypeNameSubURL}}"
|
||||||
></div>
|
></div>
|
||||||
|
|||||||
@ -7,7 +7,6 @@ const elRoot = useTemplateRef('elRoot');
|
|||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
repoLink: {type: String, required: true},
|
repoLink: {type: String, required: true},
|
||||||
repoName: {type: String, required: true},
|
|
||||||
treePath: {type: String, required: true},
|
treePath: {type: String, required: true},
|
||||||
currentRefNameSubURL: {type: String, required: true},
|
currentRefNameSubURL: {type: String, required: true},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import {pathEscapeSegments} from '../utils/url.ts';
|
|||||||
import {createElementFromHTML} from '../utils/dom.ts';
|
import {createElementFromHTML} from '../utils/dom.ts';
|
||||||
import {html} from '../utils/html.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({
|
const store = reactive({
|
||||||
rootFiles: [],
|
rootFiles: [],
|
||||||
selectedItem: props.treePath,
|
selectedItem: props.treePath,
|
||||||
@ -25,30 +25,24 @@ export function createViewFileTreeStore(props: {repoLink: string, repoName: stri
|
|||||||
},
|
},
|
||||||
|
|
||||||
async loadViewContent(url: string) {
|
async loadViewContent(url: string) {
|
||||||
url = url.includes('?') ? url.replace('?', '?only_content=true') : `${url}?only_content=true`;
|
const u = new URL(url, window.origin);
|
||||||
const response = await GET(url);
|
u.searchParams.set('only_content', '1');
|
||||||
document.querySelector('.repo-view-content').innerHTML = await response.text();
|
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) {
|
async navigateTreeView(treePath: string) {
|
||||||
const url = store.buildTreePathWebUrl(treePath);
|
const url = store.buildTreePathWebUrl(treePath);
|
||||||
const title = store.buildTitle(store.selectedItem, treePath);
|
|
||||||
window.history.pushState({treePath, url}, null, url);
|
window.history.pushState({treePath, url}, null, url);
|
||||||
store.selectedItem = treePath;
|
store.selectedItem = treePath;
|
||||||
await store.loadViewContent(url);
|
await store.loadViewContent(url);
|
||||||
document.title = title;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
buildTreePathWebUrl(treePath: string) {
|
buildTreePathWebUrl(treePath: string) {
|
||||||
return `${props.repoLink}/src/${props.currentRefNameSubURL}/${pathEscapeSegments(treePath)}`;
|
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;
|
return store;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,6 @@ export async function initRepoViewFileTree() {
|
|||||||
const fileTree = sidebar.querySelector('#view-file-tree');
|
const fileTree = sidebar.querySelector('#view-file-tree');
|
||||||
createApp(ViewFileTree, {
|
createApp(ViewFileTree, {
|
||||||
repoLink: fileTree.getAttribute('data-repo-link'),
|
repoLink: fileTree.getAttribute('data-repo-link'),
|
||||||
repoName: fileTree.getAttribute('data-repo-name'),
|
|
||||||
treePath: fileTree.getAttribute('data-tree-path'),
|
treePath: fileTree.getAttribute('data-tree-path'),
|
||||||
currentRefNameSubURL: fileTree.getAttribute('data-current-ref-name-sub-url'),
|
currentRefNameSubURL: fileTree.getAttribute('data-current-ref-name-sub-url'),
|
||||||
}).mount(fileTree);
|
}).mount(fileTree);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user