Skip to content

Commit e213e7e

Browse files
🚀 Enhances AdSense injection process in HTML files with improved error handling and checks
1 parent 95ce085 commit e213e7e

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

‎.github/workflows/website.yml‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,35 @@ jobs:
5252

5353
- name: Inject AdSense into all HTML files
5454
run: |
55-
find _site -name "*.html" -type f -exec sed -i 's|</head>|<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7596549899792751" crossorigin="anonymous"></script>\n</head>|g' {} \;
56-
echo "AdSense script injected into all HTML files"
55+
python3 << 'EOF'
56+
import os
57+
import glob
58+
59+
adsense_script = '''<!-- Google AdSense Auto Ads -->
60+
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7596549899792751" crossorigin="anonymous"></script>
61+
'''
62+
63+
html_files = glob.glob('_site/**/*.html', recursive=True)
64+
65+
for file_path in html_files:
66+
try:
67+
with open(file_path, 'r', encoding='utf-8') as f:
68+
content = f.read()
69+
70+
if '</head>' in content and 'adsbygoogle.js' not in content:
71+
content = content.replace('</head>', adsense_script + '\n</head>')
72+
73+
with open(file_path, 'w', encoding='utf-8') as f:
74+
f.write(content)
75+
76+
print(f"AdSense injected into: {file_path}")
77+
else:
78+
print(f"Skipped (no </head> or already has AdSense): {file_path}")
79+
except Exception as e:
80+
print(f"Error processing {file_path}: {e}")
81+
82+
print("AdSense injection completed")
83+
EOF
5784
5885
- name: Test site
5986
run: |
@@ -75,4 +102,4 @@ jobs:
75102
steps:
76103
- name: Deploy to GitHub Pages
77104
id: deployment
78-
uses: actions/deploy-pages@v4
105+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)