Skip to content

Commit

Permalink
Update analytics script to use environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
BramSuurdje committed Jun 14, 2024
1 parent 75e81d8 commit f5d952d
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export default function RootLayout({
<head>
<script
defer
src="https://analytics.bramsuurd.nl/script.js"
data-website-id="7e29b1b6-8b7f-4e97-a5a5-9f335d67b683"
src={process.env.NEXT_PUBLIC_ANALYTICS_URL}
data-website-id={process.env.NEXT_PUBLIC_ANALYTICS_TOKEN}
></script>
</head>
<body className={inter.className}>
Expand Down
137 changes: 137 additions & 0 deletions components/ui/codeblock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
'use client';

import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { Clipboard, Copy } from "lucide-react";
import { cn } from "@/lib/utils";
import { Separator } from "./separator";
import Link from "next/link";
import { Button } from "./button";
import { toast } from "sonner";

const buttonVariants = cva(
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90",
destructive:
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
outline:
"border border-input bg-background hover:bg-accent hover:border-primary hover:text-accent-foreground",
secondary:
"bg-secondary border-secondary text-secondary-foreground hover:bg-secondary/80 hover:border-primary",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-10 px-4 py-2",
sm: "h-9 rounded-md px-3",
lg: "h-11 rounded-md px-8",
icon: "h-10 w-10",
null: "py-1 px-3 rouded-xs",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
},
);

const handleCopy = (type: string, value: any) => {
navigator.clipboard.writeText(value);

let amountOfScriptsCopied = localStorage.getItem("amountOfScriptsCopied");

if (amountOfScriptsCopied === null) {
localStorage.setItem("amountOfScriptsCopied", "1");
} else {
amountOfScriptsCopied = (parseInt(amountOfScriptsCopied) + 1).toString();
localStorage.setItem("amountOfScriptsCopied", amountOfScriptsCopied);

if (
parseInt(amountOfScriptsCopied) === 3 ||
parseInt(amountOfScriptsCopied) === 10 ||
parseInt(amountOfScriptsCopied) === 25 ||
parseInt(amountOfScriptsCopied) === 50 ||
parseInt(amountOfScriptsCopied) === 100
) {
setTimeout(() => {
toast.info(
<div className="flex flex-col gap-3">
<p className="lg">
If you find these scripts useful, please consider starring the
repository on GitHub. It helps a lot!
</p>
<div>
<Button className="text-white">
<Link
href="https://github.com/tteck/Proxmox"
data-umami-event="Star on Github"
target="_blank"
>
Star on GitHub 💫
</Link>
</Button>
</div>
</div>,
{ duration: 8000 },
);
}, 500);
}
}

toast.success(
<div className="flex items-center gap-2">
<Clipboard className="h-4 w-4" />
<span>Copied {type} to clipboard</span>
</div>,
);
};

export interface CodeBlockProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean;
code: string;
}

const CodeBlock = React.forwardRef<HTMLDivElement, CodeBlockProps>(
({ className, variant, size, asChild = false, code }, ref) => {
const copyToClipboard = () => {
navigator.clipboard.writeText(code);
};

return (
<div
style={{
position: "relative",
marginBottom: "1rem",
display: "flex",
gap: "8px",
}}
ref={ref}
>
<pre
className={cn(
buttonVariants({ variant, size, className }),
" flex flex-row p-4",
)}
>
<p className="flex items-center gap-2">
{code} <Separator orientation="vertical" />{" "}
<Copy
className="cursor-pointer"
size={16}
onClick={() => handleCopy("install command", code)}
/>
</p>
</pre>
</div>
);
},
);
CodeBlock.displayName = "CodeBlock";

export { CodeBlock, buttonVariants };
4 changes: 3 additions & 1 deletion example.env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
NEXT_PUBLIC_POCKETBASE_URL=http://localhost:8080
NEXT_PUBLIC_POCKETBASE_URL=https://pb-phs.fly.dev
NEXT_PUBLIC_ANALYTICS_URL=
NEXT_PUBLIC_ANALYTICS_TOKEN=

0 comments on commit f5d952d

Please sign in to comment.