Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jupiter deployment fixes due to canonical url #157

Merged
merged 5 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# see https://github.com/actions/starter-workflows/blob/main/pages/jekyll.yml
name: site
on:
push: {branches: [main], tags-ignore: ['**']}
pull_request:
schedule: [{cron: '0 10 * * 6'}] # M H d m w (Sat 10:00)
permissions:
# allow GITHUB_TOKEN to deploy to GitHub Pages
contents: read
pages: write
id-token: write
Expand All @@ -21,7 +19,7 @@ jobs:
- uses: actions/setup-python@v4
with: {python-version: '3.11'}
- run: pip install -r requirements.txt pyyaml
- name: check CITATION.cff & .zenodo.json
- name: Check CITATION.cff & .zenodo.json
run: |
python <<EOF
import json, yaml
Expand Down Expand Up @@ -49,13 +47,17 @@ jobs:
- id: pages
uses: actions/configure-pages@v3
- run: pip install -r requirements.txt
- name: jupyter-book build
- name: Verify `page.html` Exists
run: |
if [ ! -f _templates/page.html ]; then
echo "Error: _templates/page.html not found!"
exit 1
fi
- name: Build Jupyter Book
run: |
sudo apt update -qq
sudo apt install -qq ghostscript fonts-freefont-otf # https://stackoverflow.com/a/69012150
sed -ri 's#^(\s*baseurl:).*#\1 ${{ steps.pages.outputs.base_url }}/'$SITE_PREFIX'#g' _config.yml
sudo apt install -qq ghostscript fonts-freefont-otf
jupyter-book build --builder dirhtml --warningiserror --nitpick --keep-going .
# fix https://github.com/executablebooks/jupyter-book/issues/2066
sed -ri 's#(.*link rel="canonical" href=".*)\.html(".*)#\1/\2#' _build/dirhtml/*/index.html
- uses: xu-cheng/latex-action@v3
with:
Expand All @@ -66,11 +68,11 @@ jobs:
env:
XINDYOPTS: -L english -C utf8 -M sphinx.xdy
continue-on-error: true
- name: prepare _site pages
- name: Prepare `_site` for Pages Deployment
run: |
mkdir _site
mv _build/dirhtml _site/$SITE_PREFIX
sed "s#DESTINATION#${{ steps.pages.outputs.base_url }}/$SITE_PREFIX#g" .redirect-template.html > _site/index.html
sed "s#DESTINATION#https://book.premai.io/$SITE_PREFIX#g" _templates/page.html > _site/index.html
- uses: actions/upload-pages-artifact@v2
deploy:
if: github.ref == 'refs/heads/main'
Expand Down
20 changes: 10 additions & 10 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ only_build_toc_files: true
exclude_patterns: [.github/*]

html:
# Removed baseurl here to avoid conflicts
# No "baseurl" here to avoid conflicts with the theme
favicon: assets/favicon.ico
use_edit_page_button: true
use_repository_button: true
Expand All @@ -30,15 +30,15 @@ parse:
This chapter is still being written & reviewed. Please do post links & discussion in the {{
'[<i class="fas fa-pencil-alt"></i> comments]({}-comments)'.format(env.docname) }} below, or {{
'[<i class="fab fa-github"></i> open a pull request]({}/edit/main/{}.md)'.format(
env.config.html_theme_options.repository_url, env.docname)
env.config.html_context.book_baseurl, env.docname)
}}!
table_feedback: |
```{admonition} Feedback
:class: attention
Is the table above outdated or missing an important model? Let us know in the {{
'[<i class="fas fa-pencil-alt"></i> comments]({}-comments)'.format(env.docname) }} below, or {{
'[<i class="fab fa-github"></i> open a pull request]({}/edit/main/{}.md)'.format(
env.config.html_theme_options.repository_url, env.docname)
env.config.html_context.book_baseurl, env.docname)
}}!
```
comments: |
Expand All @@ -48,7 +48,7 @@ parse:
:class: attention
Missing something important? Let us know in the comments below, or {{
'[<i class="fab fa-github"></i> open a pull request]({}/edit/main/{}.md)'.format(
env.config.html_theme_options.repository_url, env.docname)
env.config.html_context.book_baseurl, env.docname)
}}!
```

Expand Down Expand Up @@ -107,15 +107,15 @@ sphinx:
prem_theme: .
recursive_update: true
config:
# Add templates_path so Sphinx can see your _templates/page.html override
# Ensure Sphinx sees _templates/page.html
templates_path: ["_templates"]

# Use your custom theme
html_theme: prem_theme
html_theme_options:
# (NEW) Provide your base URL here, so you can reference it in page.html as {{ theme_options.baseurl }}
baseurl: https://book.premai.io/state-of-open-source-ai
navigation_with_keys: false
use_download_button: false

# Put your custom base URL in html_context to avoid "unsupported theme option" warnings
html_context:
book_baseurl: https://book.premai.io/state-of-open-source-ai

myst_heading_anchors: 4
html_js_files:
Expand Down
22 changes: 15 additions & 7 deletions _templates/page.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
{% extends "!page.html" %}

{% block meta %}
<link rel="canonical" href="{{ theme_options.baseurl }}/{{ pagename }}/">
<script>location="{{ theme_options.baseurl }}/{{ pagename }}/"</script>
<meta http-equiv="refresh" content="0; url={{ theme_options.baseurl }}/{{ pagename }}/">
<!-- Custom canonical link and redirect logic -->
<link rel="canonical" href="{{ book_baseurl }}/{{ pagename }}/">
<script>
location.href = "{{ book_baseurl }}/{{ pagename }}/";
</script>
<meta http-equiv="refresh" content="0; url={{ book_baseurl }}/{{ pagename }}/">
<meta name="robots" content="noindex">

{{ super() }}
{{ super() }} {# Retain any additional meta tags provided by the theme #}
{% endblock meta %}

{% block main %}
<h1>Redirecting…</h1>
<p><a href="{{ theme_options.baseurl }}/{{ pagename }}/">Click here if you are not redirected.</a></p>
{{ super() }}
<!-- Optional message for users who are not automatically redirected -->
<h1>Redirecting...</h1>
<p>
If you are not redirected automatically, please
<a href="{{ book_baseurl }}/{{ pagename }}/">click here</a>.
</p>

{{ super() }} {# Retain the normal page content provided by the theme #}
{% endblock main %}
Loading