Skip to content

Commit eb88d4c

Browse files
committed
优化广告代码,移除 AMP 自动广告元素,改为使用 Google AdSense 自动广告初始化
1 parent ac159b0 commit eb88d4c

2 files changed

Lines changed: 19 additions & 41 deletions

File tree

docusaurus.config.js

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
11
// @ts-nocheck
22
// Note: type annotations allow type checking and IDEs autocompletion
33

4-
const { themes } = require('prism-react-renderer');
5-
const lightCodeTheme = themes.github;
6-
const darkCodeTheme = themes.dracula;
7-
const oceanicNext = themes.oceanicNext;
8-
const duotoneLight = themes.duotoneLight;
4+
const lightCodeTheme = require('prism-react-renderer/themes/github')
5+
const darkCodeTheme = require('prism-react-renderer/themes/dracula')
6+
const oceanicNext = require('prism-react-renderer/themes/oceanicNext')
7+
const duotoneLight = require('prism-react-renderer/themes/duotoneLight')
98

109
// 读取环境变量
1110
require('dotenv').config();
1211

1312
/** @type {import('@docusaurus/types').Config} */
1413
const config = {
1514
title: 'gta4汉化导航站',
16-
future: {
17-
experimental_faster: true, // 启用所有性能优化,包括 Rspack
18-
},
1915
scripts: [
20-
{ src: 'https://hm.baidu.com/hm.js?de86b38bbc3dec5ed31c4da285286374', async: true }
21-
],
22-
headTags: [
23-
// Google AdSense AMP 自动广告脚本
16+
{ src: 'https://hm.baidu.com/hm.js?de86b38bbc3dec5ed31c4da285286374', async: true },
17+
// Google AdSense 标准广告脚本
2418
{
25-
tagName: 'script',
26-
attributes: {
27-
'custom-element': 'amp-auto-ads',
28-
src: 'https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js',
29-
async: 'async',
30-
},
31-
},
19+
src: 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9617969692940509',
20+
async: true,
21+
crossorigin: 'anonymous'
22+
}
3223
],
3324
// 将环境变量注入到客户端代码中
3425
customFields: {
@@ -38,10 +29,8 @@ const config = {
3829
downloadExeUrl: process.env.DOWNLOAD_EXE_URL || 'https://cloudflare-imgbed-4n1.pages.dev/file/1727106008861_GTA4汉化补丁2023-07-04.exe',
3930

4031
// 整合包下载链接
41-
// zip
42-
downloadIntegratedZipUrl: process.env.DOWNLOAD_INTEGRATED_ZIP_URL || 'https://cdn.agm.qzz.io/GTA4%E6%B1%89%E5%8C%96%E8%A1%A5%E4%B8%812025-09-07.zip',
43-
// exe
44-
downloadIntegratedExeUrl: process.env.DOWNLOAD_INTEGRATED_EXE_URL || 'https://cdn.agm.qzz.io/GTA4%E6%B1%89%E5%8C%96%E8%A1%A5%E4%B8%812025-09-07.exe',
32+
downloadIntegratedZipUrl: process.env.DOWNLOAD_INTEGRATED_ZIP_URL || 'https://dlink.host/1drv/aHR0cHM6Ly8xZHJ2Lm1zL3UvYy9mNWVkZjQyZWJmODA2MWNlL0VmbmRSVWQ1aHhSQWp4WjQxdjYwRDAwQmtmbTZSdnVpZ3Rfb3k1RGo1T00wZHc_ZT15OXA2Rlo.zip',
33+
downloadIntegratedExeUrl: process.env.DOWNLOAD_INTEGRATED_EXE_URL || 'https://acbox.app/f/22zmI8/GTA4%E6%B1%89%E5%8C%96%E8%A1%A5%E4%B8%812024-09-13.exe',
4534

4635
// 备用下载链接
4736
backupYejiUrl: process.env.BACKUP_YEJIYUN_URL || 'https://pan.huang1111.cn/s/9Q2n5Cd?path=%2F',
@@ -150,7 +139,6 @@ const config = {
150139
darkTheme: oceanicNext,
151140
// theme: duotoneLight,
152141
// darkTheme: oceanicNext,
153-
additionalLanguages: ['bash', 'diff', 'json', 'jsx', 'tsx', 'css'],
154142
},
155143
tableOfContents: {
156144
minHeadingLevel: 2,

src/theme/Root.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,14 @@ import React, { useEffect } from 'react';
22

33
export default function Root({ children }) {
44
useEffect(() => {
5-
// 创建 AMP 自动广告元素
6-
const ampAutoAds = document.createElement('amp-auto-ads');
7-
ampAutoAds.setAttribute('type', 'adsense');
8-
ampAutoAds.setAttribute('data-ad-client', 'ca-pub-9617969692940509');
9-
10-
// 将广告代码插入到 body 的开头
11-
if (document.body && document.body.firstChild) {
12-
document.body.insertBefore(ampAutoAds, document.body.firstChild);
13-
} else if (document.body) {
14-
document.body.appendChild(ampAutoAds);
15-
}
16-
17-
// 清理函数
18-
return () => {
19-
if (ampAutoAds && ampAutoAds.parentNode) {
20-
ampAutoAds.parentNode.removeChild(ampAutoAds);
5+
// 初始化 Google AdSense 自动广告
6+
try {
7+
if (window.adsbygoogle && window.adsbygoogle.loaded !== true) {
8+
(window.adsbygoogle = window.adsbygoogle || []).push({});
219
}
22-
};
10+
} catch (err) {
11+
console.error('AdSense error:', err);
12+
}
2313
}, []);
2414

2515
return <>{children}</>;

0 commit comments

Comments
 (0)