mirror of
https://gitcode.com/gitea/gitea.git
synced 2025-05-22 09:37:48 +08:00
Refactor issue page info (#32445)
Fix a longstanding TODO since 2021 (#14826) / 2018 (#2531)
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import {encode, decode} from 'uint8-to-base64';
|
||||
import type {IssuePathInfo} from './types.ts';
|
||||
import {decode, encode} from 'uint8-to-base64';
|
||||
import type {IssuePageInfo, IssuePathInfo} from './types.ts';
|
||||
|
||||
// transform /path/to/file.ext to file.ext
|
||||
export function basename(path: string): string {
|
||||
@ -43,6 +43,16 @@ export function parseIssueNewHref(href: string): IssuePathInfo {
|
||||
return {ownerName, repoName, pathType, indexString};
|
||||
}
|
||||
|
||||
export function parseIssuePageInfo(): IssuePageInfo {
|
||||
const el = document.querySelector('#issue-page-info');
|
||||
return {
|
||||
issueNumber: parseInt(el?.getAttribute('data-issue-index')),
|
||||
issueDependencySearchType: el?.getAttribute('data-issue-dependency-search-type') || '',
|
||||
repoId: parseInt(el?.getAttribute('data-issue-repo-id')),
|
||||
repoLink: el?.getAttribute('data-issue-repo-link') || '',
|
||||
};
|
||||
}
|
||||
|
||||
// parse a URL, either relative '/path' or absolute 'https://localhost/path'
|
||||
export function parseUrl(str: string): URL {
|
||||
return new URL(str, str.startsWith('http') ? undefined : window.location.origin);
|
||||
|
Reference in New Issue
Block a user