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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixes to redirect issues in deployment
AlessandroMicagni committed Jan 20, 2025
commit 9d813016bcc349fb84807196a2363b818c2022c3
150 changes: 90 additions & 60 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -1,77 +1,107 @@
# see https://github.com/actions/starter-workflows/blob/main/pages/jekyll.yml
# .github/workflows/site.yml
name: site

on:
push: {branches: [main], tags-ignore: ['**']}
push:
branches: [main]
tags-ignore: ['**']
pull_request:
schedule: [{cron: '0 10 * * 6'}] # M H d m w (Sat 10:00)
schedule:
- cron: '0 10 * * 6' # Runs at 10:00 UTC every Saturday

permissions:
# allow GITHUB_TOKEN to deploy to GitHub Pages
contents: read
pages: write
id-token: write
concurrency: {group: "${{ github.ref }}-pages", cancel-in-progress: true}

concurrency:
group: "${{ github.ref }}-pages"
cancel-in-progress: true

env:
SITE_PREFIX: state-of-open-source-ai

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: {fetch-depth: 0}
- uses: actions/setup-python@v4
with: {python-version: '3.11'}
- run: pip install -r requirements.txt pyyaml
- name: check CITATION.cff & .zenodo.json
run: |
python <<EOF
import json, yaml
cff = yaml.safe_load(open("CITATION.cff"))
zen = json.load(open(".zenodo.json"))

assert cff['title'] == zen['title'] + " Book"
assert len(cff['authors']) - 1 == len(zen['creators'])
for cauth, zauth in zip(cff['authors'][:-1], zen['creators']):
assert zauth['name'] == f"{cauth['family-names']}, {cauth['given-names']}"
assert zauth.get('affiliation', "") == cauth.get('affiliation', "")
assert zauth.get('orcid', "") == cauth.get('orcid', "").rsplit("/", 1)[-1]
assert [{'name': cff['authors'][-1]['name'], 'type': "Other"}] == zen['contributors']
assert cff['abstract'] == zen['description']
assert cff['url'] == zen['related_identifiers'][0]['identifier']
assert cff['keywords'] == zen['keywords']
EOF
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v4
with:
python-version: '3.11'

- run: pip install -r requirements.txt pyyaml

- name: Check CITATION.cff & .zenodo.json
run: |
python <<EOF
import json, yaml
cff = yaml.safe_load(open("CITATION.cff"))
zen = json.load(open(".zenodo.json"))

assert cff['title'] == zen['title'] + " Book"
assert len(cff['authors']) - 1 == len(zen['creators'])
for cauth, zauth in zip(cff['authors'][:-1], zen['creators']):
assert zauth['name'] == f"{cauth['family-names']}, {cauth['given-names']}"
assert zauth.get('affiliation', "") == cauth.get('affiliation', "")
assert zauth.get('orcid', "") == cauth.get('orcid', "").rsplit("/", 1)[-1]
assert [{'name': cff['authors'][-1]['name'], 'type': "Other"}] == zen['contributors']
assert cff['abstract'] == zen['description']
assert cff['url'] == zen['related_identifiers'][0]['identifier']
assert cff['keywords'] == zen['keywords']
EOF

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: {fetch-depth: 0}
- uses: actions/setup-python@v4
with: {python-version: '3.11'}
- id: pages
uses: actions/configure-pages@v3
- run: pip install -r requirements.txt
- name: jupyter-book build
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
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:
working_directory: _build/latex
root_file: book.tex
args: -pdf -dvi- -ps- -file-line-error -f -interaction=nonstopmode
latexmk_use_xelatex: true
env:
XINDYOPTS: -L english -C utf8 -M sphinx.xdy
continue-on-error: true
- name: prepare _site pages
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
- uses: actions/upload-pages-artifact@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v4
with:
python-version: '3.11'

- id: pages
uses: actions/configure-pages@v3

- run: pip install -r requirements.txt

- name: Jupyter Book Build
run: |
sudo apt update -qq
sudo apt install -qq ghostscript fonts-freefont-otf # Install necessary packages

# Build the book in dirhtml format, treating warnings as errors
jupyter-book build --builder dirhtml --warningiserror --nitpick --keep-going .

# Fix canonical links to remove .html suffix
sed -ri 's#(.*link rel="canonical" href=".*)\.html(".*)#\1/\2#' _build/dirhtml/*/index.html

# Removed LaTeX build step to prevent 'book.tex' not found error

- name: Prepare _site Pages
run: |
mkdir _site
mv _build/dirhtml _site/$SITE_PREFIX

# Create a minimal root redirect (optional)
echo '<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=https://book.premai.io/state-of-open-source-ai/">
<title>Redirecting…</title>
</head>
<body>
<p>Redirecting to <a href="https://book.premai.io/state-of-open-source-ai/">State of Open Source AI</a>.</p>
</body>
</html>' > _site/index.html

- uses: actions/upload-pages-artifact@v2

deploy:
if: github.ref == 'refs/heads/main'
environment:
@@ -80,5 +110,5 @@ jobs:
runs-on: ubuntu-latest
needs: [check, build]
steps:
- id: deployment
uses: actions/deploy-pages@v2
- id: deployment
uses: actions/deploy-pages@v2
15 changes: 5 additions & 10 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ only_build_toc_files: true
exclude_patterns: [.github/*]

html:
# Note: No "baseurl" here to avoid conflicts with the theme
# No "baseurl" here to avoid conflicts with the theme
favicon: assets/favicon.ico
use_edit_page_button: true
use_repository_button: true
@@ -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: |
@@ -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)
}}!
```

@@ -113,12 +113,7 @@ sphinx:
# Use your custom theme
html_theme: prem_theme

# Theme options: only those recognized by prem_theme
html_theme_options:
navigation_with_keys: false
use_download_button: false

# Put your custom base URL in html_context instead of html_theme_options
# 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

19 changes: 10 additions & 9 deletions _templates/page.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{% extends "!page.html" %}

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

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

{% block main %}
<!-- Optional message for those who aren't auto-redirected -->
<h1>Redirecting</h1>
<!-- Optional message for users who are not automatically redirected -->
<h1>Redirecting...</h1>
<p>
<a href="{{ book_baseurl }}/{{ pagename }}/">
Click here if you are not redirected.
</a>
If you are not redirected automatically, please
<a href="{{ book_baseurl }}/{{ pagename }}/">click here</a>.
</p>

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