Skip to content

Commit 8d23289

Browse files
committed
attempt fix
1 parent 29ece5e commit 8d23289

File tree

5 files changed

+138
-11
lines changed

5 files changed

+138
-11
lines changed

.github/workflows/gh-pages.yml

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,114 @@ on:
55
types: [created]
66
pull_request:
77
branches: [main]
8+
push:
9+
branches: [main]
810

911
jobs:
1012
build:
1113
runs-on: ubuntu-latest
1214
steps:
1315
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0 # Fetch all history for proper versioning
18+
1419
- uses: actions/setup-python@v5
1520
with:
1621
python-version: "3.13"
22+
1723
- name: Install dependencies
1824
run: pip install -e ".[dev]"
25+
26+
- name: Determine version and build type
27+
id: version
28+
run: |
29+
if [[ "${{ github.event_name }}" == "release" ]]; then
30+
echo "VERSION=stable" >> $GITHUB_OUTPUT
31+
echo "DIR=stable" >> $GITHUB_OUTPUT
32+
echo "TAG=${{ github.ref_name }}" >> $GITHUB_OUTPUT
33+
elif [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then
34+
echo "VERSION=latest" >> $GITHUB_OUTPUT
35+
echo "DIR=latest" >> $GITHUB_OUTPUT
36+
echo "TAG=main" >> $GITHUB_OUTPUT
37+
else
38+
echo "VERSION=latest" >> $GITHUB_OUTPUT
39+
echo "DIR=latest" >> $GITHUB_OUTPUT
40+
echo "TAG=pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
41+
fi
42+
1943
- name: Generate versions.json
2044
run: |
45+
# Create a more comprehensive versions.json
2146
cat <<EOF > docs/versions.json
2247
[
2348
{
2449
"version": "latest",
25-
"url": "/xarray-dataclass/latest/"
50+
"url": "https://xarray-contrib.github.io/xarray-dataclass/latest/",
51+
"name": "latest"
2652
},
2753
{
2854
"version": "stable",
29-
"url": "/xarray-dataclass/stable/"
55+
"url": "https://xarray-contrib.github.io/xarray-dataclass/stable/",
56+
"name": "stable"
3057
}
3158
]
3259
EOF
60+
3361
- name: Build docs
3462
run: |
35-
# Set DOCS_VERSION env var according to event
36-
if [[ "${{ github.event_name }}" == "release" ]]; then
37-
export DOCS_VERSION=stable
38-
else
39-
export DOCS_VERSION=latest
40-
fi
63+
# Set DOCS_VERSION env var according to determined version
64+
export DOCS_VERSION=${{ steps.version.outputs.VERSION }}
65+
echo "Building documentation for version: $DOCS_VERSION"
4166
67+
# Build the documentation
4268
python -m sphinx -b html docs docs/_build
69+
4370
- name: Copy versions.json to build output
4471
run: cp docs/versions.json docs/_build/
72+
73+
- name: Create 404 page for GitHub Pages
74+
if: ${{ github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/main') }}
75+
run: |
76+
# Create a symlink of the 404.html file in the root directory for GitHub Pages
77+
# This ensures that the 404 page is used for all missing pages across all versions
78+
cp docs/_build/404.html docs/_build/404.html.bak
79+
cat <<EOF > docs/_build/404.html
80+
<!DOCTYPE html>
81+
<html>
82+
<head>
83+
<meta charset="UTF-8">
84+
<meta http-equiv="refresh" content="0; url=./latest/404.html">
85+
<title>Page Not Found</title>
86+
</head>
87+
<body>
88+
<p>If you are not redirected automatically, follow this <a href="./latest/404.html">link to the 404 page</a>.</p>
89+
</body>
90+
</html>
91+
EOF
92+
# Restore the original 404.html in the version directory
93+
mv docs/_build/404.html.bak docs/_build/404.html
94+
95+
- name: Create redirect index.html
96+
if: ${{ github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/main') }}
97+
run: |
98+
# Create a root index.html that redirects to the stable version (or latest if no stable exists)
99+
cat <<EOF > docs/_build/index.html
100+
<!DOCTYPE html>
101+
<html>
102+
<head>
103+
<meta charset="UTF-8">
104+
<meta http-equiv="refresh" content="0; url=./${{ steps.version.outputs.DIR }}/">
105+
<title>Redirect to ${{ steps.version.outputs.VERSION }} documentation</title>
106+
</head>
107+
<body>
108+
<p>If you are not redirected automatically, follow this <a href="./${{ steps.version.outputs.DIR }}/">link to the ${{ steps.version.outputs.VERSION }} documentation</a>.</p>
109+
</body>
110+
</html>
111+
EOF
112+
45113
- name: Deploy docs
46114
uses: peaceiris/actions-gh-pages@v3
47115
with:
48116
github_token: ${{ secrets.GITHUB_TOKEN }}
49117
publish_dir: ./docs/_build
50-
destination_dir: ${{ github.event_name == 'release' && 'stable' || 'latest' }}
118+
destination_dir: ${{ steps.version.outputs.DIR }}

docs/404.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Page Not Found
2+
3+
The page you requested could not be found. It might have been moved, renamed, or might not exist.
4+
5+
## Possible reasons:
6+
7+
1. The URL might be incorrect
8+
2. The page might have been moved or renamed
9+
3. The page might have been removed
10+
4. You might be looking at a different version of the documentation
11+
12+
## What to do next:
13+
14+
- Check the URL for typos
15+
- Try using the search function to find what you're looking for
16+
- Go to the [home page](index.html) and navigate from there
17+
- Try switching to a different version of the documentation using the version switcher in the navigation bar

docs/_templates/layout.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{# Extend the theme's layout #}
2+
{% extends "!layout.html" %}
3+
4+
{# Add custom elements to the page #}
5+
{% block extrahead %}
6+
{{ super() }}
7+
<meta name="docsearch:version" content="{{ version }}">
8+
{% endblock %}
9+
10+
{# Add version information for the current page #}
11+
{% block footer %}
12+
{{ super() }}
13+
<script>
14+
// Add version information to the current page
15+
document.addEventListener('DOMContentLoaded', function() {
16+
// This helps search engines and other tools understand the version of the page
17+
var meta = document.createElement('meta');
18+
meta.name = 'version';
19+
meta.content = '{{ version }}';
20+
document.head.appendChild(meta);
21+
});
22+
</script>
23+
{% endblock %}

docs/conf.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import os
2+
from datetime import datetime
23

3-
version = os.environ.get("DOCS_VERSION", "unknown")
4+
# Get version from environment variable or use "dev" as fallback
5+
version = os.environ.get("DOCS_VERSION", "dev")
46
release = version
57

8+
# Get current year for copyright
9+
current_year = datetime.now().year
10+
611
# project information
12+
project = "xarray-dataclass"
713
author = "Wouter-Michiel Vierdag"
8-
copyright = "2025 Wouter-Michiel Vierdag"
14+
copyright = f"{current_year} Wouter-Michiel Vierdag"
915

1016

1117
# general configuration
@@ -43,4 +49,16 @@
4349
"navbar_end": ["version-switcher", "navbar-icon-links"],
4450
"github_url": "https://github.com/xarray-contrib/xarray-dataclass/",
4551
"twitter_url": "https://x.com/xarray_dev/",
52+
"use_edit_page_button": True,
53+
"show_prev_next": False,
54+
"icon_links": [
55+
{
56+
"name": "PyPI",
57+
"url": "https://pypi.org/project/xarray-dataclass/",
58+
"icon": "fa-solid fa-box",
59+
},
60+
],
61+
"external_links": [
62+
{"name": "xarray", "url": "https://xarray.pydata.org/"},
63+
],
4664
}

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ hidden:
88
99
Home <self>
1010
Package guide <_apidoc/xarray_dataclasses>
11+
404 <404>
1112
```

0 commit comments

Comments
 (0)