Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/deploy-gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Deploy Static Site to GitHub Pages

on:
push:
branches: ["main"]
workflow_dispatch:

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build static index.html from Select-product-page.jsx
run: |
python3 - << 'PYEOF'
import re, os

with open('Select-product-page.jsx', 'r') as f:
content = f.read()

# Replace ES module import with global React reference using regex
# to handle variations in whitespace or quote style
component_code = re.sub(
r'''import\s*\{\s*useState\s*\}\s*from\s*['"]react['"];?''',
'const { useState } = React;',
content
)
# Remove export default so MensHealthCombined is a plain function in browser scope
component_code = re.sub(
r'\bexport\s+default\s+function\s+',
'function ',
component_code
)

html = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hormone Experts – Men's Health</title>
<script crossorigin src="https://unpkg.com/react@17.0.2/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone@7.23.10/babel.min.js"></script>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: #000; }
</style>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
""" + component_code + """
ReactDOM.render(<MensHealthCombined />, document.getElementById('root'));
</script>
</body>
</html>
"""

os.makedirs('gh-pages-dist', exist_ok=True)
with open('gh-pages-dist/index.html', 'w') as f:
f.write(html)

print(f"Generated gh-pages-dist/index.html ({len(html)} bytes)")
PYEOF

- name: Deploy to gh-pages branch
uses: peaceiris/actions-gh-pages@v3.9.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./gh-pages-dist
publish_branch: gh-pages
force_orphan: true
commit_message: "Deploy Hormone Experts product page to GitHub Pages"
Loading
Loading