File tree Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Original file line number Diff line number Diff line change 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 : |
75102 steps :
76103 - name : Deploy to GitHub Pages
77104 id : deployment
78- uses : actions/deploy-pages@v4
105+ uses : actions/deploy-pages@v4
You can’t perform that action at this time.
0 commit comments