6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
80 lines
2.3 KiB
TypeScript
80 lines
2.3 KiB
TypeScript
"use client";
|
|
|
|
import type { CSSProperties } from "react";
|
|
import { useEffect, useRef } from "react";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
const ADSENSE_CLIENT_ID = process.env.NEXT_PUBLIC_GOOGLE_ADSENSE_CLIENT_ID;
|
|
|
|
declare global {
|
|
interface Window {
|
|
adsbygoogle?: Record<string, unknown>[];
|
|
}
|
|
}
|
|
|
|
interface AdUnitProps {
|
|
/** AdSense ad slot ID from your AdSense dashboard. */
|
|
slot: string;
|
|
/** AdSense ad format. Defaults to "auto" for responsive display ads. */
|
|
format?: "auto" | "fluid" | "rectangle" | "vertical" | "horizontal";
|
|
/** Optional layout (e.g. "in-article"). */
|
|
layout?: string;
|
|
/** Optional layout key (required for in-feed ads). */
|
|
layoutKey?: string;
|
|
/** Full-width responsive on mobile. Defaults to true. */
|
|
responsive?: boolean;
|
|
className?: string;
|
|
style?: CSSProperties;
|
|
}
|
|
|
|
/**
|
|
* Renders a Google AdSense ad unit. Requires <AdSenseScript /> to be mounted
|
|
* on the same page. Renders nothing if NEXT_PUBLIC_GOOGLE_ADSENSE_CLIENT_ID
|
|
* is unset or if `slot` is empty (so missing-slot env vars stay invisible).
|
|
*/
|
|
export function AdUnit({
|
|
slot,
|
|
format = "auto",
|
|
layout,
|
|
layoutKey,
|
|
responsive = true,
|
|
className,
|
|
style,
|
|
}: AdUnitProps) {
|
|
const insRef = useRef<HTMLModElement>(null);
|
|
|
|
useEffect(() => {
|
|
if (!ADSENSE_CLIENT_ID || !slot) return;
|
|
const el = insRef.current;
|
|
if (!el) return;
|
|
// Guard against duplicate pushes (React StrictMode dev double-invoke,
|
|
// client-side navigation back to this page, or HMR remounts). AdSense
|
|
// sets data-adsbygoogle-status="done" once it has filled a slot.
|
|
if (el.getAttribute("data-adsbygoogle-status")) return;
|
|
try {
|
|
window.adsbygoogle = window.adsbygoogle || [];
|
|
window.adsbygoogle.push({});
|
|
} catch {
|
|
// AdSense throws if pushed before the script has loaded or on
|
|
// duplicate pushes. The script processes pending pushes when it
|
|
// finishes loading, so we can safely swallow this.
|
|
}
|
|
}, [slot]);
|
|
|
|
if (!ADSENSE_CLIENT_ID || !slot) return null;
|
|
|
|
return (
|
|
<ins
|
|
ref={insRef}
|
|
className={cn("adsbygoogle block", className)}
|
|
style={{ display: "block", ...style }}
|
|
data-ad-client={ADSENSE_CLIENT_ID}
|
|
data-ad-slot={slot}
|
|
data-ad-format={format}
|
|
data-ad-layout={layout}
|
|
data-ad-layout-key={layoutKey}
|
|
data-full-width-responsive={responsive ? "true" : "false"}
|
|
/>
|
|
);
|
|
}
|