11import { Button } from "@/components/ui/button" ;
22import { basePath } from "@/config/siteConfig" ;
33import { Script } from "@/lib/types" ;
4- import { BookOpenText , Code , Globe } from "lucide-react" ;
4+ import { BookOpenText , Code , Globe , RefreshCcw } from "lucide-react" ;
55import Link from "next/link" ;
66
7- const generateSourceUrl = ( slug : string , type : string ) => {
7+ const generateInstallSourceUrl = ( slug : string ) => {
88 const baseUrl = `https://raw.githubusercontent.com/community-scripts/${ basePath } /main` ;
9- return type === "ct"
10- ? `${ baseUrl } /install/${ slug } -install.sh`
11- : `${ baseUrl } /${ type } /${ slug } .sh` ;
9+ return `${ baseUrl } /install/${ slug } -install.sh` ;
10+ } ;
11+
12+ const generateSourceUrl = ( slug : string ) => {
13+ const baseUrl = `https://raw.githubusercontent.com/community-scripts/${ basePath } /main` ;
14+ return `${ baseUrl } /misc/${ slug } .sh` ;
15+ } ;
16+
17+ const generateUpdateUrl = ( slug : string ) => {
18+ const baseUrl = `https://raw.githubusercontent.com/community-scripts/${ basePath } /main` ;
19+ return `${ baseUrl } /update/${ slug } -update.sh` ;
1220} ;
1321
1422interface ButtonLinkProps {
@@ -29,20 +37,35 @@ const ButtonLink = ({ href, icon, text }: ButtonLinkProps) => (
2937) ;
3038
3139export default function Buttons ( { item } : { item : Script } ) {
40+ const isCtOrDefault = [ "ct" ] . includes ( item . type ) ;
41+ const installSourceUrl = isCtOrDefault ? generateInstallSourceUrl ( item . slug ) : null ;
42+ const updateSourceUrl = isCtOrDefault ? generateUpdateUrl ( item . slug ) : null ;
43+ const sourceUrl = ! isCtOrDefault ? generateSourceUrl ( item . slug ) : null ;
44+
3245 const buttons = [
3346 item . website && {
3447 href : item . website ,
35- icon : < Globe className = "h-4 w-4" /> ,
48+ icon : < Globe className = "h-4 w-4" /> ,
3649 text : "Website" ,
3750 } ,
3851 item . documentation && {
3952 href : item . documentation ,
40- icon : < BookOpenText className = "h-4 w-4" /> ,
53+ icon : < BookOpenText className = "h-4 w-4" /> ,
4154 text : "Documentation" ,
4255 } ,
43- {
44- href : generateSourceUrl ( item . slug , item . type ) ,
45- icon : < Code className = "h-4 w-4" /> ,
56+ installSourceUrl && {
57+ href : installSourceUrl ,
58+ icon : < Code className = "h-4 w-4" /> ,
59+ text : "Install-Source" ,
60+ } ,
61+ updateSourceUrl && {
62+ href : updateSourceUrl ,
63+ icon : < RefreshCcw className = "h-4 w-4" /> ,
64+ text : "Update-Source" ,
65+ } ,
66+ sourceUrl && {
67+ href : sourceUrl ,
68+ icon : < Code className = "h-4 w-4" /> ,
4669 text : "Source Code" ,
4770 } ,
4871 ] . filter ( Boolean ) as ButtonLinkProps [ ] ;
0 commit comments