Skip to content

Commit 9d81301

Browse files
fixes to redirect issues in deployment
1 parent 13a6e7c commit 9d81301

File tree

3 files changed

+105
-79
lines changed

3 files changed

+105
-79
lines changed

.github/workflows/pages.yml

Lines changed: 90 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,107 @@
1-
# see https://github.com/actions/starter-workflows/blob/main/pages/jekyll.yml
1+
# .github/workflows/site.yml
22
name: site
3+
34
on:
4-
push: {branches: [main], tags-ignore: ['**']}
5+
push:
6+
branches: [main]
7+
tags-ignore: ['**']
58
pull_request:
6-
schedule: [{cron: '0 10 * * 6'}] # M H d m w (Sat 10:00)
9+
schedule:
10+
- cron: '0 10 * * 6' # Runs at 10:00 UTC every Saturday
11+
712
permissions:
8-
# allow GITHUB_TOKEN to deploy to GitHub Pages
913
contents: read
1014
pages: write
1115
id-token: write
12-
concurrency: {group: "${{ github.ref }}-pages", cancel-in-progress: true}
16+
17+
concurrency:
18+
group: "${{ github.ref }}-pages"
19+
cancel-in-progress: true
20+
1321
env:
1422
SITE_PREFIX: state-of-open-source-ai
23+
1524
jobs:
1625
check:
1726
runs-on: ubuntu-latest
1827
steps:
19-
- uses: actions/checkout@v4
20-
with: {fetch-depth: 0}
21-
- uses: actions/setup-python@v4
22-
with: {python-version: '3.11'}
23-
- run: pip install -r requirements.txt pyyaml
24-
- name: check CITATION.cff & .zenodo.json
25-
run: |
26-
python <<EOF
27-
import json, yaml
28-
cff = yaml.safe_load(open("CITATION.cff"))
29-
zen = json.load(open(".zenodo.json"))
30-
31-
assert cff['title'] == zen['title'] + " Book"
32-
assert len(cff['authors']) - 1 == len(zen['creators'])
33-
for cauth, zauth in zip(cff['authors'][:-1], zen['creators']):
34-
assert zauth['name'] == f"{cauth['family-names']}, {cauth['given-names']}"
35-
assert zauth.get('affiliation', "") == cauth.get('affiliation', "")
36-
assert zauth.get('orcid', "") == cauth.get('orcid', "").rsplit("/", 1)[-1]
37-
assert [{'name': cff['authors'][-1]['name'], 'type': "Other"}] == zen['contributors']
38-
assert cff['abstract'] == zen['description']
39-
assert cff['url'] == zen['related_identifiers'][0]['identifier']
40-
assert cff['keywords'] == zen['keywords']
41-
EOF
28+
- uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
32+
- uses: actions/setup-python@v4
33+
with:
34+
python-version: '3.11'
35+
36+
- run: pip install -r requirements.txt pyyaml
37+
38+
- name: Check CITATION.cff & .zenodo.json
39+
run: |
40+
python <<EOF
41+
import json, yaml
42+
cff = yaml.safe_load(open("CITATION.cff"))
43+
zen = json.load(open(".zenodo.json"))
44+
45+
assert cff['title'] == zen['title'] + " Book"
46+
assert len(cff['authors']) - 1 == len(zen['creators'])
47+
for cauth, zauth in zip(cff['authors'][:-1], zen['creators']):
48+
assert zauth['name'] == f"{cauth['family-names']}, {cauth['given-names']}"
49+
assert zauth.get('affiliation', "") == cauth.get('affiliation', "")
50+
assert zauth.get('orcid', "") == cauth.get('orcid', "").rsplit("/", 1)[-1]
51+
assert [{'name': cff['authors'][-1]['name'], 'type': "Other"}] == zen['contributors']
52+
assert cff['abstract'] == zen['description']
53+
assert cff['url'] == zen['related_identifiers'][0]['identifier']
54+
assert cff['keywords'] == zen['keywords']
55+
EOF
56+
4257
build:
4358
runs-on: ubuntu-latest
4459
steps:
45-
- uses: actions/checkout@v4
46-
with: {fetch-depth: 0}
47-
- uses: actions/setup-python@v4
48-
with: {python-version: '3.11'}
49-
- id: pages
50-
uses: actions/configure-pages@v3
51-
- run: pip install -r requirements.txt
52-
- name: jupyter-book build
53-
run: |
54-
sudo apt update -qq
55-
sudo apt install -qq ghostscript fonts-freefont-otf # https://stackoverflow.com/a/69012150
56-
sed -ri 's#^(\s*baseurl:).*#\1 ${{ steps.pages.outputs.base_url }}/'$SITE_PREFIX'#g' _config.yml
57-
jupyter-book build --builder dirhtml --warningiserror --nitpick --keep-going .
58-
# fix https://github.com/executablebooks/jupyter-book/issues/2066
59-
sed -ri 's#(.*link rel="canonical" href=".*)\.html(".*)#\1/\2#' _build/dirhtml/*/index.html
60-
- uses: xu-cheng/latex-action@v3
61-
with:
62-
working_directory: _build/latex
63-
root_file: book.tex
64-
args: -pdf -dvi- -ps- -file-line-error -f -interaction=nonstopmode
65-
latexmk_use_xelatex: true
66-
env:
67-
XINDYOPTS: -L english -C utf8 -M sphinx.xdy
68-
continue-on-error: true
69-
- name: prepare _site pages
70-
run: |
71-
mkdir _site
72-
mv _build/dirhtml _site/$SITE_PREFIX
73-
sed "s#DESTINATION#${{ steps.pages.outputs.base_url }}/$SITE_PREFIX#g" .redirect-template.html > _site/index.html
74-
- uses: actions/upload-pages-artifact@v2
60+
- uses: actions/checkout@v4
61+
with:
62+
fetch-depth: 0
63+
64+
- uses: actions/setup-python@v4
65+
with:
66+
python-version: '3.11'
67+
68+
- id: pages
69+
uses: actions/configure-pages@v3
70+
71+
- run: pip install -r requirements.txt
72+
73+
- name: Jupyter Book Build
74+
run: |
75+
sudo apt update -qq
76+
sudo apt install -qq ghostscript fonts-freefont-otf # Install necessary packages
77+
78+
# Build the book in dirhtml format, treating warnings as errors
79+
jupyter-book build --builder dirhtml --warningiserror --nitpick --keep-going .
80+
81+
# Fix canonical links to remove .html suffix
82+
sed -ri 's#(.*link rel="canonical" href=".*)\.html(".*)#\1/\2#' _build/dirhtml/*/index.html
83+
84+
# Removed LaTeX build step to prevent 'book.tex' not found error
85+
86+
- name: Prepare _site Pages
87+
run: |
88+
mkdir _site
89+
mv _build/dirhtml _site/$SITE_PREFIX
90+
91+
# Create a minimal root redirect (optional)
92+
echo '<!DOCTYPE html>
93+
<html>
94+
<head>
95+
<meta http-equiv="refresh" content="0; url=https://book.premai.io/state-of-open-source-ai/">
96+
<title>Redirecting…</title>
97+
</head>
98+
<body>
99+
<p>Redirecting to <a href="https://book.premai.io/state-of-open-source-ai/">State of Open Source AI</a>.</p>
100+
</body>
101+
</html>' > _site/index.html
102+
103+
- uses: actions/upload-pages-artifact@v2
104+
75105
deploy:
76106
if: github.ref == 'refs/heads/main'
77107
environment:
@@ -80,5 +110,5 @@ jobs:
80110
runs-on: ubuntu-latest
81111
needs: [check, build]
82112
steps:
83-
- id: deployment
84-
uses: actions/deploy-pages@v2
113+
- id: deployment
114+
uses: actions/deploy-pages@v2

_config.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ only_build_toc_files: true
1111
exclude_patterns: [.github/*]
1212

1313
html:
14-
# Note: No "baseurl" here to avoid conflicts with the theme
14+
# No "baseurl" here to avoid conflicts with the theme
1515
favicon: assets/favicon.ico
1616
use_edit_page_button: true
1717
use_repository_button: true
@@ -30,15 +30,15 @@ parse:
3030
This chapter is still being written & reviewed. Please do post links & discussion in the {{
3131
'[<i class="fas fa-pencil-alt"></i> comments]({}-comments)'.format(env.docname) }} below, or {{
3232
'[<i class="fab fa-github"></i> open a pull request]({}/edit/main/{}.md)'.format(
33-
env.config.html_theme_options.repository_url, env.docname)
33+
env.config.html_context.book_baseurl, env.docname)
3434
}}!
3535
table_feedback: |
3636
```{admonition} Feedback
3737
:class: attention
3838
Is the table above outdated or missing an important model? Let us know in the {{
3939
'[<i class="fas fa-pencil-alt"></i> comments]({}-comments)'.format(env.docname) }} below, or {{
4040
'[<i class="fab fa-github"></i> open a pull request]({}/edit/main/{}.md)'.format(
41-
env.config.html_theme_options.repository_url, env.docname)
41+
env.config.html_context.book_baseurl, env.docname)
4242
}}!
4343
```
4444
comments: |
@@ -48,7 +48,7 @@ parse:
4848
:class: attention
4949
Missing something important? Let us know in the comments below, or {{
5050
'[<i class="fab fa-github"></i> open a pull request]({}/edit/main/{}.md)'.format(
51-
env.config.html_theme_options.repository_url, env.docname)
51+
env.config.html_context.book_baseurl, env.docname)
5252
}}!
5353
```
5454
@@ -113,12 +113,7 @@ sphinx:
113113
# Use your custom theme
114114
html_theme: prem_theme
115115

116-
# Theme options: only those recognized by prem_theme
117-
html_theme_options:
118-
navigation_with_keys: false
119-
use_download_button: false
120-
121-
# Put your custom base URL in html_context instead of html_theme_options
116+
# Put your custom base URL in html_context to avoid "unsupported theme option" warnings
122117
html_context:
123118
book_baseurl: https://book.premai.io/state-of-open-source-ai
124119

_templates/page.html

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
{% extends "!page.html" %}
22

33
{% block meta %}
4-
<!-- Custom canonical link & redirect -->
4+
<!-- Custom canonical link and redirect logic -->
55
<link rel="canonical" href="{{ book_baseurl }}/{{ pagename }}/">
6-
<script>location="{{ book_baseurl }}/{{ pagename }}/"</script>
6+
<script>
7+
location.href = "{{ book_baseurl }}/{{ pagename }}/";
8+
</script>
79
<meta http-equiv="refresh" content="0; url={{ book_baseurl }}/{{ pagename }}/">
810
<meta name="robots" content="noindex">
911

10-
{{ super() }} {# Keep other meta tags the theme provides #}
12+
{{ super() }} {# Retain any additional meta tags provided by the theme #}
1113
{% endblock meta %}
1214

1315
{% block main %}
14-
<!-- Optional message for those who aren't auto-redirected -->
15-
<h1>Redirecting</h1>
16+
<!-- Optional message for users who are not automatically redirected -->
17+
<h1>Redirecting...</h1>
1618
<p>
17-
<a href="{{ book_baseurl }}/{{ pagename }}/">
18-
Click here if you are not redirected.
19-
</a>
19+
If you are not redirected automatically, please
20+
<a href="{{ book_baseurl }}/{{ pagename }}/">click here</a>.
2021
</p>
2122

22-
{{ super() }} {# Keep the normal page content #}
23+
{{ super() }} {# Retain the normal page content provided by the theme #}
2324
{% endblock main %}

0 commit comments

Comments
 (0)