2022-08-16 17:42:26 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -uex
|
|
|
|
|
2024-04-27 05:12:11 +00:00
|
|
|
rustup update nightly
|
2022-08-16 17:42:26 +00:00
|
|
|
rustup default nightly
|
|
|
|
|
2022-08-19 13:30:54 +00:00
|
|
|
PYO3_VERSION=$(cargo search pyo3 --limit 1 | head -1 | tr -s ' ' | cut -d ' ' -f 3 | tr -d '"')
|
2022-12-26 09:12:25 +00:00
|
|
|
|
|
|
|
## Start from the existing gh-pages content.
|
2023-01-08 19:45:19 +00:00
|
|
|
## By serving it over netlify, we can have better UX for users because
|
2022-12-26 09:12:25 +00:00
|
|
|
## netlify can then redirect e.g. /v0.17.0 to /v0.17.0/
|
|
|
|
## which leads to better loading of CSS assets.
|
|
|
|
|
|
|
|
wget -qc https://github.com/PyO3/pyo3/archive/gh-pages.tar.gz -O - | tar -xz
|
|
|
|
mv pyo3-gh-pages netlify_build
|
2022-08-19 13:30:54 +00:00
|
|
|
|
|
|
|
## Configure netlify _redirects file
|
|
|
|
|
2023-01-10 08:20:57 +00:00
|
|
|
# Add redirect for each documented version
|
2023-06-21 20:35:06 +00:00
|
|
|
set +x # these loops get very spammy and fill the deploy log
|
|
|
|
|
2023-01-10 08:20:57 +00:00
|
|
|
for d in netlify_build/v*; do
|
|
|
|
version="${d/netlify_build\/v/}"
|
|
|
|
echo "/v$version/doc/* https://docs.rs/pyo3/$version/:splat" >> netlify_build/_redirects
|
2023-06-21 20:35:06 +00:00
|
|
|
if [ $version != $PYO3_VERSION ]; then
|
|
|
|
# for old versions, mark the files in the latest version as the canonical URL
|
|
|
|
for file in $(find $d -type f); do
|
|
|
|
file_path="${file/$d\//}"
|
|
|
|
# remove index.html and/or .html suffix to match the page URL on the
|
|
|
|
# final netlfiy site
|
|
|
|
url_path="$file_path"
|
|
|
|
if [[ $file_path == index.html ]]; then
|
|
|
|
url_path=""
|
|
|
|
elif [[ $file_path == *.html ]]; then
|
|
|
|
url_path="${file_path%.html}"
|
|
|
|
fi
|
|
|
|
echo "/v$version/$url_path" >> netlify_build/_headers
|
|
|
|
if test -f "netlify_build/v$PYO3_VERSION/$file_path"; then
|
|
|
|
echo " Link: <https://pyo3.rs/v$PYO3_VERSION/$url_path>; rel=\"canonical\"" >> netlify_build/_headers
|
|
|
|
else
|
|
|
|
# this file doesn't exist in the latest guide, don't index it
|
|
|
|
echo " X-Robots-Tag: noindex" >> netlify_build/_headers
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2023-01-10 08:20:57 +00:00
|
|
|
done
|
2022-08-19 13:30:54 +00:00
|
|
|
|
2023-01-08 19:55:24 +00:00
|
|
|
# Add latest redirect
|
2023-06-21 20:35:06 +00:00
|
|
|
echo "/latest/* /v${PYO3_VERSION}/:splat 302" >> netlify_build/_redirects
|
2022-08-19 13:30:54 +00:00
|
|
|
|
2024-03-09 20:10:58 +00:00
|
|
|
# some backwards compatbiility redirects
|
|
|
|
echo "/latest/building_and_distribution/* /latest/building-and-distribution/:splat 302" >> netlify_build/_redirects
|
|
|
|
echo "/latest/building-and-distribution/multiple_python_versions/* /latest/building-and-distribution/multiple-python-versions:splat 302" >> netlify_build/_redirects
|
|
|
|
echo "/latest/function/error_handling/* /latest/function/error-handling/:splat 302" >> netlify_build/_redirects
|
|
|
|
echo "/latest/getting_started/* /latest/getting-started/:splat 302" >> netlify_build/_redirects
|
|
|
|
echo "/latest/python_from_rust/* /latest/python-from-rust/:splat 302" >> netlify_build/_redirects
|
|
|
|
echo "/latest/python_typing_hints/* /latest/python-typing-hints/:splat 302" >> netlify_build/_redirects
|
|
|
|
echo "/latest/trait_bounds/* /latest/trait-bounds/:splat 302" >> netlify_build/_redirects
|
|
|
|
|
2022-08-19 13:30:54 +00:00
|
|
|
## Add landing page redirect
|
2022-09-07 02:11:09 +00:00
|
|
|
if [ "${CONTEXT}" == "deploy-preview" ]; then
|
2023-01-10 08:20:57 +00:00
|
|
|
echo "/ /main/" >> netlify_build/_redirects
|
2022-09-07 02:11:09 +00:00
|
|
|
else
|
2023-06-21 20:35:06 +00:00
|
|
|
echo "/ /v${PYO3_VERSION}/ 302" >> netlify_build/_redirects
|
2022-09-07 02:11:09 +00:00
|
|
|
fi
|
2022-08-19 13:30:54 +00:00
|
|
|
|
2023-06-21 20:35:06 +00:00
|
|
|
set -x
|
2022-09-08 06:58:53 +00:00
|
|
|
## Generate towncrier release notes
|
|
|
|
|
|
|
|
pip install towncrier
|
|
|
|
towncrier build --yes --version Unreleased --date TBC
|
2022-08-19 13:30:54 +00:00
|
|
|
|
|
|
|
## Build guide
|
|
|
|
|
2022-08-16 17:42:26 +00:00
|
|
|
# Install latest mdbook. Netlify will cache the cargo bin dir, so this will
|
|
|
|
# only build mdbook if needed.
|
|
|
|
MDBOOK_VERSION=$(cargo search mdbook --limit 1 | head -1 | tr -s ' ' | cut -d ' ' -f 3 | tr -d '"')
|
|
|
|
INSTALLED_MDBOOK_VERSION=$(mdbook --version || echo "none")
|
|
|
|
if [ "${INSTALLED_MDBOOK_VERSION}" != "mdbook v${MDBOOK_VERSION}" ]; then
|
2022-11-30 08:31:00 +00:00
|
|
|
cargo install mdbook@${MDBOOK_VERSION} --force
|
2022-08-16 17:42:26 +00:00
|
|
|
fi
|
|
|
|
|
2024-03-08 14:10:47 +00:00
|
|
|
# Install latest mdbook-linkcheck. Netlify will cache the cargo bin dir, so this will
|
|
|
|
# only build mdbook-linkcheck if needed.
|
|
|
|
MDBOOK_LINKCHECK_VERSION=$(cargo search mdbook-linkcheck --limit 1 | head -1 | tr -s ' ' | cut -d ' ' -f 3 | tr -d '"')
|
|
|
|
INSTALLED_MDBOOK_LINKCHECK_VERSION=$(mdbook-linkcheck --version || echo "none")
|
|
|
|
if [ "${INSTALLED_MDBOOK_LINKCHECK_VERSION}" != "mdbook v${MDBOOK_LINKCHECK_VERSION}" ]; then
|
|
|
|
cargo install mdbook-linkcheck@${MDBOOK_LINKCHECK_VERSION} --force
|
|
|
|
fi
|
|
|
|
|
2022-08-16 17:42:26 +00:00
|
|
|
pip install nox
|
|
|
|
nox -s build-guide
|
2024-03-08 14:10:47 +00:00
|
|
|
mv target/guide/ netlify_build/main/
|
2022-08-16 17:42:26 +00:00
|
|
|
|
2022-08-19 13:30:54 +00:00
|
|
|
## Build public docs
|
|
|
|
|
2023-06-05 15:12:30 +00:00
|
|
|
nox -s docs
|
2022-08-16 17:42:26 +00:00
|
|
|
mv target/doc netlify_build/main/doc/
|
|
|
|
|
2022-09-07 06:46:24 +00:00
|
|
|
echo "<meta http-equiv=refresh content=0;url=pyo3/>" > netlify_build/main/doc/index.html
|
|
|
|
|
2022-08-19 13:30:54 +00:00
|
|
|
## Build internal docs
|
2022-08-16 17:42:26 +00:00
|
|
|
|
2023-06-08 21:04:48 +00:00
|
|
|
nox -s docs -- nightly internal
|
2022-08-16 17:42:26 +00:00
|
|
|
|
2022-08-19 13:30:54 +00:00
|
|
|
mkdir -p netlify_build/internal
|
|
|
|
mv target/doc netlify_build/internal/
|
2022-08-16 17:42:26 +00:00
|
|
|
|
|
|
|
ls -l netlify_build/
|