From 230841dcd710d01d9099c630df057bfdd4fd5817 Mon Sep 17 00:00:00 2001 From: Bram Suurd Date: Sat, 8 Jun 2024 21:51:19 +0200 Subject: [PATCH] refactor: Transform source URL to install script URL in ScriptItem component --- components/Script.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/components/Script.tsx b/components/Script.tsx index 3cceb03..a6c5db4 100644 --- a/components/Script.tsx +++ b/components/Script.tsx @@ -58,13 +58,24 @@ function ScriptItem({ }, [item, pattern]); const sourceUrl = useMemo(() => { + const transformUrlToInstallScript = (url: string) => { + if (url.includes("/misc/") || url.includes("/vm/")) { + return url; + } else if (url.includes("/ct/")) { + return url.replace("/ct/", "/install/").replace(/\.sh$/, "-install.sh"); + } + return url; + }; + if (installCommand) { const match = installCommand.match(pattern); - return match ? match[0] : null; + return match ? transformUrlToInstallScript(match[0]) : null; } return null; }, [installCommand, pattern]); + + const handleCopy = (type: string, value: any) => { navigator.clipboard.writeText(value);