Skip to content

Commit

Permalink
feat: add convert logo link function
Browse files Browse the repository at this point in the history
  • Loading branch information
0xExp-po committed Sep 13, 2024
1 parent f205696 commit 25e2e2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dapp/src/components/ProjectInfo.astro
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ import ModalInput from "./utils/ModalInput.astro";
import { initializeProjectState, loadConfigData, loadProjectInfo, setProject } from "../service/StateService";
import type { ConfigData } from "../types/projectConfig";
import { projectInfoLoaded } from "../utils/store";
import { convertGitHubLink } from "../utils/editLinkFunctions";

document.addEventListener("astro:page-load", () => {
initializeProjectState();
Expand Down Expand Up @@ -350,7 +351,7 @@ import ModalInput from "./utils/ModalInput.astro";
if (modalProjectName) modalProjectName.textContent = projectInfo.name;
if (projectLogo) {
if (configData.logoImageLink) {
projectLogo.src = configData.logoImageLink;
projectLogo.src = convertGitHubLink(configData.logoImageLink);
projectLogo.style.display = 'block';
} else {
projectLogo.style.display = 'none';
Expand Down
12 changes: 12 additions & 0 deletions dapp/src/utils/editLinkFunctions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function convertGitHubLink(link: string): string {
const githubFileRegex = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/blob\/(.+)$/;

const match = link.match(githubFileRegex);

if (match) {
const [, owner, repo, path] = match;
return `https://raw.githubusercontent.com/${owner}/${repo}/${path}`;
} else {
return link;
}
}

0 comments on commit 25e2e2a

Please sign in to comment.