Skip to content

fixed the error due to which the left nav was unable to render #5

fixed the error due to which the left nav was unable to render

fixed the error due to which the left nav was unable to render #5

Workflow file for this run

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
- 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.png"
favicon_ico_path = f"{prefix}/assets/images/favicon.ico"
# Replace favicon link tags
content = re.sub(
r'<link[^>]*rel=["\'](?:shortcut )?icon["\'][^>]*>',
f'<link rel="icon" href="{favicon_ico_path}">\n <link rel="icon" type="image/png" href="{favicon_path}">',
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_ico_path}">\n <link rel="icon" type="image/png" href="{favicon_path}">\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="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