add Google AdSense auto-ads loader

Shares the same publisher account as qipaobuzz / hype404
(ca-pub-9763775565109295). site.ads = { enabled: true, publisherId };
Layout conditionally injects the adsbygoogle.js loader in <head> when
ads are enabled — Google auto-ads handles placement.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude Code
2026-05-01 18:30:44 +08:00
parent 4428636492
commit b18887a8f3
2 changed files with 13 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ const {
const pageTitle = title || site.name; const pageTitle = title || site.name;
const ogUrl = canonical || Astro.url.toString(); const ogUrl = canonical || Astro.url.toString();
const year = new Date().getFullYear(); const year = new Date().getFullYear();
const ads = site.ads;
--- ---
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
@@ -45,6 +46,14 @@ const year = new Date().getFullYear();
<link rel="alternate" type="application/rss+xml" title={`${site.name} RSS`} href="/rss.xml" /> <link rel="alternate" type="application/rss+xml" title={`${site.name} RSS`} href="/rss.xml" />
{ads?.enabled && (
<script
async
src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-${ads.publisherId}`}
crossorigin="anonymous"
/>
)}
<link rel="preconnect" href="https://fonts.googleapis.com" /> <link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700;9..144,800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Bungee+Shade&family=Bungee&display=swap" rel="stylesheet" /> <link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700;9..144,800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Bungee+Shade&family=Bungee&display=swap" rel="stylesheet" />

View File

@@ -3,4 +3,8 @@ export const site = {
description: "Where the internet's MVPs go viral", description: "Where the internet's MVPs go viral",
url: 'https://viralmvp.com', url: 'https://viralmvp.com',
postsPerPage: 10, postsPerPage: 10,
ads: {
enabled: true,
publisherId: '9763775565109295',
},
}; };