Skip to content

Commit

Permalink
style: 🚨 Fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffJacobson committed Sep 30, 2024
1 parent fec9f56 commit 456e0de
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/utils/Github-Link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ export const githubPagesUrlRe =
export type GithubRepoUrl = `https://www.github.com/${string}/${string}`;
export type GithubPagesUrl = `https://${string}.github.io/${string}`;

/**
* Get the source URL of a Github Pages page.
* @param throwErrorOnMismatch - If true, throw an error if URL can't
* be parsed. Otherwise, null will be returned.
* @returns A URL
*/

export function getGithubUrlFromGithubPages(
throwErrorOnMismatch: true,
githubPagesUrl?: GithubPagesUrl,
Expand All @@ -22,12 +17,20 @@ export function getGithubUrlFromGithubPages(
throwErrorOnMismatch?: false,
githubPagesUrl?: GithubPagesUrl,
): GithubRepoUrl | null;
/**
* Get the source URL of a Github Pages page.
* @param throwErrorOnMismatch - If true, throw an error if URL can't
* @param githubPagesUrl - Specify the GitHub Pages URL if you don't
* want to use the default of location.href.
* be parsed. Otherwise, null will be returned.
* @returns A URL
*/
export function getGithubUrlFromGithubPages(
throwErrorOnMismatch?: boolean,
githubPagesUrl?: GithubPagesUrl,
) {
const currentUrl = githubPagesUrl ?? location.href;
const match = currentUrl.match(githubPagesUrlRe);
const match = githubPagesUrlRe.exec(currentUrl);
if (!match) {
if (throwErrorOnMismatch) {
throw new Error("Could not parse source URL from this page");
Expand All @@ -52,7 +55,7 @@ export function createGithubLink(
const a = document.createElement("a");
// a.append(githubSvg);
a.textContent = "Source code";
a.href = getGithubUrlFromGithubPages() || fallbackUrl;
a.href = getGithubUrlFromGithubPages() ?? fallbackUrl;
a.target = "_blank";
return a;
}

0 comments on commit 456e0de

Please sign in to comment.