Skip to content

Commit 81d36c6

Browse files
jupiter deployment fixes due to canonical url (#157)
* jupiter deployment fixes due to canonical url * fixes to url contetxt * fixes to redirect issues in deployment * fix indentetion issue * Fix workflow and redirect logic with updated page.html
1 parent 275bf49 commit 81d36c6

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

.github/workflows/pages.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
# see https://github.com/actions/starter-workflows/blob/main/pages/jekyll.yml
21
name: site
32
on:
43
push: {branches: [main], tags-ignore: ['**']}
54
pull_request:
65
schedule: [{cron: '0 10 * * 6'}] # M H d m w (Sat 10:00)
76
permissions:
8-
# allow GITHUB_TOKEN to deploy to GitHub Pages
97
contents: read
108
pages: write
119
id-token: write
@@ -21,7 +19,7 @@ jobs:
2119
- uses: actions/setup-python@v4
2220
with: {python-version: '3.11'}
2321
- run: pip install -r requirements.txt pyyaml
24-
- name: check CITATION.cff & .zenodo.json
22+
- name: Check CITATION.cff & .zenodo.json
2523
run: |
2624
python <<EOF
2725
import json, yaml
@@ -49,13 +47,17 @@ jobs:
4947
- id: pages
5048
uses: actions/configure-pages@v3
5149
- run: pip install -r requirements.txt
52-
- name: jupyter-book build
50+
- name: Verify `page.html` Exists
51+
run: |
52+
if [ ! -f _templates/page.html ]; then
53+
echo "Error: _templates/page.html not found!"
54+
exit 1
55+
fi
56+
- name: Build Jupyter Book
5357
run: |
5458
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
59+
sudo apt install -qq ghostscript fonts-freefont-otf
5760
jupyter-book build --builder dirhtml --warningiserror --nitpick --keep-going .
58-
# fix https://github.com/executablebooks/jupyter-book/issues/2066
5961
sed -ri 's#(.*link rel="canonical" href=".*)\.html(".*)#\1/\2#' _build/dirhtml/*/index.html
6062
- uses: xu-cheng/latex-action@v3
6163
with:
@@ -66,11 +68,11 @@ jobs:
6668
env:
6769
XINDYOPTS: -L english -C utf8 -M sphinx.xdy
6870
continue-on-error: true
69-
- name: prepare _site pages
71+
- name: Prepare `_site` for Pages Deployment
7072
run: |
7173
mkdir _site
7274
mv _build/dirhtml _site/$SITE_PREFIX
73-
sed "s#DESTINATION#${{ steps.pages.outputs.base_url }}/$SITE_PREFIX#g" .redirect-template.html > _site/index.html
75+
sed "s#DESTINATION#https://book.premai.io/$SITE_PREFIX#g" _templates/page.html > _site/index.html
7476
- uses: actions/upload-pages-artifact@v2
7577
deploy:
7678
if: github.ref == 'refs/heads/main'

_config.yml

Lines changed: 10 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-
# Removed baseurl here to avoid conflicts
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
@@ -107,15 +107,15 @@ sphinx:
107107
prem_theme: .
108108
recursive_update: true
109109
config:
110-
# Add templates_path so Sphinx can see your _templates/page.html override
110+
# Ensure Sphinx sees _templates/page.html
111111
templates_path: ["_templates"]
112112

113+
# Use your custom theme
113114
html_theme: prem_theme
114-
html_theme_options:
115-
# (NEW) Provide your base URL here, so you can reference it in page.html as {{ theme_options.baseurl }}
116-
baseurl: https://book.premai.io/state-of-open-source-ai
117-
navigation_with_keys: false
118-
use_download_button: false
115+
116+
# Put your custom base URL in html_context to avoid "unsupported theme option" warnings
117+
html_context:
118+
book_baseurl: https://book.premai.io/state-of-open-source-ai
119119

120120
myst_heading_anchors: 4
121121
html_js_files:

_templates/page.html

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

33
{% block meta %}
4-
<link rel="canonical" href="{{ theme_options.baseurl }}/{{ pagename }}/">
5-
<script>location="{{ theme_options.baseurl }}/{{ pagename }}/"</script>
6-
<meta http-equiv="refresh" content="0; url={{ theme_options.baseurl }}/{{ pagename }}/">
4+
<!-- Custom canonical link and redirect logic -->
5+
<link rel="canonical" href="{{ book_baseurl }}/{{ pagename }}/">
6+
<script>
7+
location.href = "{{ book_baseurl }}/{{ pagename }}/";
8+
</script>
9+
<meta http-equiv="refresh" content="0; url={{ book_baseurl }}/{{ pagename }}/">
710
<meta name="robots" content="noindex">
811

9-
{{ super() }}
12+
{{ super() }} {# Retain any additional meta tags provided by the theme #}
1013
{% endblock meta %}
1114

1215
{% block main %}
13-
<h1>Redirecting…</h1>
14-
<p><a href="{{ theme_options.baseurl }}/{{ pagename }}/">Click here if you are not redirected.</a></p>
15-
{{ super() }}
16+
<!-- Optional message for users who are not automatically redirected -->
17+
<h1>Redirecting...</h1>
18+
<p>
19+
If you are not redirected automatically, please
20+
<a href="{{ book_baseurl }}/{{ pagename }}/">click here</a>.
21+
</p>
22+
23+
{{ super() }} {# Retain the normal page content provided by the theme #}
1624
{% endblock main %}

0 commit comments

Comments
 (0)