mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: handle file changes path properly
This commit is contained in:
parent
3cf4deaa9f
commit
6331892329
3 changed files with 16 additions and 11 deletions
|
|
@ -151,7 +151,7 @@ export async function getPullPageDocuments(
|
|||
document?: Document,
|
||||
) {
|
||||
if (document) {
|
||||
return continuousLoadFragmentedPages(document)
|
||||
return continuousLoadFragmentedPages(window.location.href, document)
|
||||
}
|
||||
// Response of this contains view of few files but is not complete.
|
||||
return continuousLoadFragmentedPagesFromUrl(`/${userName}/${repoName}/pull/${pullId}/files`)
|
||||
|
|
@ -162,7 +162,7 @@ export async function getCommitPageDocuments() {
|
|||
repoName: string,
|
||||
commitId: string, */
|
||||
// arguments are not used because info are collected from DOM directly
|
||||
return continuousLoadFragmentedPages(document)
|
||||
return continuousLoadFragmentedPages(window.location.href, document)
|
||||
}
|
||||
|
||||
export async function getBlobData(
|
||||
|
|
|
|||
|
|
@ -151,7 +151,13 @@ export function isInPullFilesPage() {
|
|||
}
|
||||
|
||||
export function getIssueTitle() {
|
||||
const title = $('.gh-header-title')?.textContent
|
||||
const title = $(
|
||||
[
|
||||
'.gh-header-title .markdown-title', // exclude issue ID from title
|
||||
'.gh-header-title',
|
||||
'[data-component="TitleArea"] [data-component="PH_Title"]', // PR new experience title
|
||||
].join(),
|
||||
)?.textContent
|
||||
return title?.trim().replace(/\n/g, '')
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,13 +76,14 @@ export function resolveHeaderLink(raw: string) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function getDOM(url: string) {
|
||||
async function getDOM(url: string) {
|
||||
const res = await fetch(url)
|
||||
const content = await res.text()
|
||||
return new DOMParser().parseFromString(content, 'text/html')
|
||||
return [res.url, new DOMParser().parseFromString(content, 'text/html')] as const
|
||||
}
|
||||
|
||||
export async function continuousLoadFragmentedPages(
|
||||
url: string,
|
||||
doc: Document,
|
||||
docs: Document[] = [],
|
||||
): Promise<[string, Document[]]> {
|
||||
|
|
@ -108,17 +109,15 @@ export async function continuousLoadFragmentedPages(
|
|||
const src = fragment.getAttribute('src')
|
||||
if (src) {
|
||||
// Using `src` without origin below would fail in Firefox if the src is an absolute path
|
||||
await continuousLoadFragmentedPagesFromUrl(src, docs)
|
||||
return await continuousLoadFragmentedPagesFromUrl(src, docs)
|
||||
}
|
||||
}
|
||||
return [new URL(doc.baseURI).pathname, docs]
|
||||
return [new URL(url).pathname, docs]
|
||||
}
|
||||
|
||||
export async function continuousLoadFragmentedPagesFromUrl(url: string, docs: Document[] = []) {
|
||||
return continuousLoadFragmentedPages(
|
||||
await getDOM(new URL(url, window.location.origin).href),
|
||||
docs,
|
||||
)
|
||||
const [finalUrl, dom] = await getDOM(new URL(url, window.location.origin).href)
|
||||
return continuousLoadFragmentedPages(finalUrl, dom, docs)
|
||||
}
|
||||
|
||||
export function getCommentsMap(commentData: GitHubAPI.PullComments) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue