Refactor issue page info (#32445)
Fix a longstanding TODO since 2021 (#14826) / 2018 (#2531)
This commit is contained in:
parent
028e612094
commit
623a2d41cc
8 changed files with 36 additions and 27 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue