-
Notifications
You must be signed in to change notification settings - Fork 0
231 lines (202 loc) · 8.54 KB
/
deploy.yml
File metadata and controls
231 lines (202 loc) · 8.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: Documentation
on:
push:
branches:
- main
permissions:
contents: read
pages: write
id-token: write
jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- uses: actions/configure-pages@v5
with:
enablement: true
token: ${{ secrets.PAGES_DEPLOY_TOKEN || github.token }}
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install Zensical
run: pip install zensical
- name: Configure for GitHub Pages
env:
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }}
run: |
python3 << 'EOF'
import re
import os
import glob
owner = os.environ.get('GITHUB_REPOSITORY_OWNER', '')
repo_name = os.environ.get('GITHUB_REPOSITORY_NAME', '')
# Determine site_url for GitHub Pages
if repo_name.lower() == owner.lower():
site_url = f"https://{owner}.github.io/"
else:
site_url = f"https://{owner}.github.io/{repo_name}/"
toml_files = sorted(glob.glob('zensical*.toml'))
if not toml_files:
raise RuntimeError("No zensical*.toml files found")
pattern = r'site_url\s*=\s*["\'][^"\']*["\']'
for path in toml_files:
with open(path, 'r', encoding='utf-8') as f:
content = f.read()
content = re.sub(pattern, f'site_url = "{site_url}"', content)
# Ensure use_directory_urls is set (Zensical also forces false for offline usage)
if 'use_directory_urls' not in content:
content = re.sub(
r'(site_url\s*=\s*"[^"]*")',
r'\1\nuse_directory_urls = true',
content,
count=1
)
with open(path, 'w', encoding='utf-8') as f:
f.write(content)
print(f"✓ Configured site_url in {path}: {site_url}")
EOF
- name: Build site
run: |
rm -rf site
zensical build --clean --config-file zensical.toml
zensical build --clean --config-file zensical.es.toml
zensical build --clean --config-file zensical.pt.toml
zensical build --clean --config-file zensical.pt-BR.toml
- name: Fix asset paths for GitHub Pages
env:
GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
run: |
python3 << 'FIXPATHS'
import os
import re
repo_name = os.environ.get('GITHUB_REPOSITORY_NAME', '')
owner = os.environ.get('GITHUB_REPOSITORY_OWNER', '')
# Determine base path
if repo_name.lower() == owner.lower():
base_path = ""
else:
base_path = f"/{repo_name}"
# Find all HTML files
html_files = []
for root, dirs, files in os.walk('site'):
for file in files:
if file.endswith('.html'):
html_files.append(os.path.join(root, file))
print(f"Processing {len(html_files)} HTML files")
print(f"Base path: {base_path or '/'}")
files_modified = 0
for html_file in html_files:
with open(html_file, 'r', encoding='utf-8') as f:
content = f.read()
original = content
# Determine language prefix from file location:
# site/<lang>/... -> prefix "/<base>/<lang>"
rel = os.path.relpath(html_file, 'site')
lang = rel.split(os.sep, 1)[0]
prefix = f"{base_path}/{lang}" if base_path else f"/{lang}"
# Fix CSS/JS asset paths: convert relative to absolute with base path
# Fix href="assets/..." -> href="/repo/<lang>/assets/..."
content = re.sub(
r'href=(["\'])(?!/|https?://|//)(assets/[^"\']+)',
lambda m: f'href={m.group(1)}{prefix}/{m.group(2)}{m.group(1)}',
content
)
# Fix src="assets/..." -> src="/repo/<lang>/assets/..."
content = re.sub(
r'src=(["\'])(?!/|https?://|//)(assets/[^"\']+)',
lambda m: f'src={m.group(1)}{prefix}/{m.group(2)}{m.group(1)}',
content
)
# Fix language selector links (configured as /en/, /es/, ...)
if base_path:
content = re.sub(
r'href=(["\'])(/(?:en|es|pt|pt-BR)/)(["\'])',
lambda m: f'href={m.group(1)}{base_path}{m.group(2)}{m.group(3)}',
content
)
if content != original:
with open(html_file, 'w', encoding='utf-8') as f:
f.write(content)
files_modified += 1
print(f"✓ Fixed asset paths in {files_modified} files")
# Fix favicon links in HTML head - ensure omegaUp favicon is used
favicon_fixed = 0
for html_file in html_files:
with open(html_file, 'r', encoding='utf-8') as f:
content = f.read()
original = content
rel = os.path.relpath(html_file, 'site')
lang = rel.split(os.sep, 1)[0]
prefix = f"{base_path}/{lang}" if base_path else f"/{lang}"
favicon_path = f"{prefix}/assets/images/favicon-76x76.png"
# Replace favicon link tags
content = re.sub(
r'<link[^>]*rel=["\'](?:shortcut )?icon["\'][^>]*>',
f'<link rel="icon" href="{favicon_path}" type="image/png">',
content,
flags=re.IGNORECASE
)
# Also ensure favicon is in head if missing
if '<link rel="icon"' not in content.lower():
# Insert before </head>
content = re.sub(
r'(</head>)',
f' <link rel="icon" href="{favicon_path}" type="image/png">\n\\1',
content,
flags=re.IGNORECASE
)
if content != original:
with open(html_file, 'w', encoding='utf-8') as f:
f.write(content)
favicon_fixed += 1
if favicon_fixed > 0:
print(f"✓ Fixed favicon links in {favicon_fixed} files")
# Add .nojekyll to site directory
with open('site/.nojekyll', 'w') as f:
f.write('')
print("✓ Created .nojekyll")
# Add redirect from / -> /en/
import textwrap
redirect_html = textwrap.dedent("""\
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="refresh" content="0; url=./en/" />
<link rel="icon" href="./en/assets/images/favicon-76x76.png" type="image/png" />
<link rel="canonical" href="./en/" />
<title>omegaUp Documentation</title>
<script>
(function() {
var target = './en/';
if (location.pathname.endsWith('/') || location.pathname.endsWith('/index.html')) {
location.replace(target);
} else {
location.replace(location.pathname.replace(/[^/]*$/, '') + target);
}
})();
</script>
</head>
<body>
<p>Redirecting to <a href="./en/">English documentation</a>…</p>
</body>
</html>
""")
with open('site/index.html', 'w', encoding='utf-8') as f:
f.write(redirect_html)
print("✓ Created / -> /en/ redirect (site/index.html)")
FIXPATHS
- uses: actions/upload-pages-artifact@v4
with:
path: site
- uses: actions/deploy-pages@v4
id: deployment
with:
token: ${{ secrets.PAGES_DEPLOY_TOKEN || github.token }}