From 910afdeb714e94ed3115b943fba743d58031f5d1 Mon Sep 17 00:00:00 2001 From: gunshiz Date: Wed, 16 Sep 2026 20:19:27 +0700 Subject: [PATCH] feat : dev on prod --- .env.example | 3 +++ .gitea/workflows/ci.yml | 2 ++ Dockerfile | 2 ++ app/Ads.txt | 1 - app/[character]/[page]/page.tsx | 8 +++++++- app/[character]/page.tsx | 8 +++++++- app/page.tsx | 2 ++ components/public/google-adsense.tsx | 30 ++++++++++++++++++++++++++++ public/ads.txt | 1 + tests/deployment-contract.test.ts | 13 +++++++++++- tests/public-performance.test.ts | 21 +++++++++++++++++++ 11 files changed, 87 insertions(+), 4 deletions(-) delete mode 100644 app/Ads.txt create mode 100644 components/public/google-adsense.tsx create mode 100644 public/ads.txt diff --git a/.env.example b/.env.example index d9967c5..17a2c88 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,9 @@ # Public site origin used for SEO metadata, sitemap, and robots.txt. BASE_URL=https://guide.sudloh.com +# Public AdSense publisher client ID. Leave unset to disable ads locally. +NEXT_PUBLIC_GOOGLE_ADSENSE_CLIENT_ID=ca-pub-9687404323559597 + # Local-only demo mode serves sanitized fixtures and bypasses external services. # Keep this false in every deployed environment. BUZZ_DEMO_MODE=false diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 581bd04..8255476 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -10,6 +10,7 @@ on: env: BASE_URL: https://guide.sudloh.com + NEXT_PUBLIC_GOOGLE_ADSENSE_CLIENT_ID: ca-pub-9687404323559597 REGISTRY_IMAGE: registry.neko-piranha.ts.net/astral/buzz-sheet DEPLOY_NAMESPACE: buzz-sheet KUBE_API_SERVER: https://100.112.189.33:6443/ @@ -32,6 +33,7 @@ jobs: docker build \ --target app \ --build-arg BASE_URL="$BASE_URL" \ + --build-arg NEXT_PUBLIC_GOOGLE_ADSENSE_CLIENT_ID="$NEXT_PUBLIC_GOOGLE_ADSENSE_CLIENT_ID" \ --build-arg NEXT_DEPLOYMENT_ID=${{ gitea.sha }} \ --build-arg VCS_REF=${{ gitea.sha }} \ --tag ${{ env.REGISTRY_IMAGE }}:${{ gitea.sha }} \ diff --git a/Dockerfile b/Dockerfile index 918e1f8..4f44637 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,8 +23,10 @@ FROM node:22-bookworm-slim AS next-builder WORKDIR /app ARG NEXT_DEPLOYMENT_ID=container-build ARG BASE_URL +ARG NEXT_PUBLIC_GOOGLE_ADSENSE_CLIENT_ID ENV BASE_URL=${BASE_URL} ENV NEXT_DEPLOYMENT_ID=${NEXT_DEPLOYMENT_ID} +ENV NEXT_PUBLIC_GOOGLE_ADSENSE_CLIENT_ID=${NEXT_PUBLIC_GOOGLE_ADSENSE_CLIENT_ID} ENV NEXT_TELEMETRY_DISABLED=1 COPY --from=dependencies /app/node_modules ./node_modules COPY . . diff --git a/app/Ads.txt b/app/Ads.txt deleted file mode 100644 index 0552972..0000000 --- a/app/Ads.txt +++ /dev/null @@ -1 +0,0 @@ -google.com, pub-9687404323559597, DIRECT, f08c47fec0942fa0 \ No newline at end of file diff --git a/app/[character]/[page]/page.tsx b/app/[character]/[page]/page.tsx index 0bd61b1..3fee79f 100644 --- a/app/[character]/[page]/page.tsx +++ b/app/[character]/[page]/page.tsx @@ -1,6 +1,7 @@ import type { Metadata } from "next"; import { notFound } from "next/navigation"; +import { GoogleAdsense } from "@/components/public/google-adsense"; import { publicSections, StructuredGuideShell } from "@/components/public/structured-guide"; import { getCachedPublicGuide } from "@/lib/cache/public"; @@ -25,5 +26,10 @@ export default async function GuideSectionPage({ params }: { params: Params }) { const { character, page } = await params; const guide = await getCachedPublicGuide(character); if (!guide || !publicSections(guide).some((section) => section.slug === page)) notFound(); - return ; + return ( + <> + + + + ); } diff --git a/app/[character]/page.tsx b/app/[character]/page.tsx index 61e0acb..f70b63f 100644 --- a/app/[character]/page.tsx +++ b/app/[character]/page.tsx @@ -1,6 +1,7 @@ import type { Metadata } from "next"; import { notFound } from "next/navigation"; +import { GoogleAdsense } from "@/components/public/google-adsense"; import { StructuredGuideShell } from "@/components/public/structured-guide"; import { getCachedPublicGuide } from "@/lib/cache/public"; @@ -31,5 +32,10 @@ export default async function GuideOverviewPage({ }) { const guide = await getCachedPublicGuide((await params).character); if (!guide) notFound(); - return ; + return ( + <> + + + + ); } diff --git a/app/page.tsx b/app/page.tsx index d34fa5c..0ab4767 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -2,6 +2,7 @@ import { connection } from "next/server"; import { Suspense } from "react"; import { LiveRefresh } from "@/components/live-refresh"; +import { GoogleAdsense } from "@/components/public/google-adsense"; import { SiteFooter } from "@/components/public/site-footer"; import { StructuredDirectory } from "@/components/public/structured-directory"; import { SiteHeader } from "@/components/public/site-header"; @@ -16,6 +17,7 @@ async function DirectoryContent() { export default function HomePage() { return (
+
diff --git a/components/public/google-adsense.tsx b/components/public/google-adsense.tsx new file mode 100644 index 0000000..f86357a --- /dev/null +++ b/components/public/google-adsense.tsx @@ -0,0 +1,30 @@ +"use client"; + +import Script from "next/script"; + +import { authClient } from "@/lib/auth/client"; + +const clientId = process.env.NEXT_PUBLIC_GOOGLE_ADSENSE_CLIENT_ID?.trim(); + +export function GoogleAdsense() { + const { data: session, error, isPending } = authClient.useSession(); + + if ( + process.env.NODE_ENV !== "production" || + !clientId || + isPending || + error || + session + ) { + return null; + } + + return ( +