Refactor issue page info (#32445)

Fix a longstanding TODO since 2021 (#14826) / 2018 (#2531)
This commit is contained in:
wxiaoguang 2024-11-08 10:21:13 +08:00 committed by GitHub
parent 028e612094
commit 623a2d41cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 36 additions and 27 deletions

View file

@ -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);