Skip to content

Commit

Permalink
set base url for readthedocs (#224)
Browse files Browse the repository at this point in the history
* set base url via build.py

Co-authored-by: Sviatoslav Sydorenko <[email protected]>

* use python 3.11 consistently

* set rtd canonical url

---------

Co-authored-by: Sviatoslav Sydorenko <[email protected]>
  • Loading branch information
oraNod and webknjaz authored Feb 28, 2024
1 parent cfee94f commit 8a5df32
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: >-
python: >- # Python versions should match the noxfile as well as the constraint files.
3.11
commands:
- python -m venv "${READTHEDOCS_VIRTUALENV_PATH}"
Expand All @@ -15,4 +15,4 @@ build:
pip install nox
- >-
"${READTHEDOCS_VIRTUALENV_PATH}"/bin/python -Im
nox -s build -- "${READTHEDOCS_OUTPUT}"/html
nox -s build -- "${READTHEDOCS_OUTPUT}"/html "${READTHEDOCS_CANONICAL_URL}"
22 changes: 17 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import shutil
import sys
from functools import partial
from pathlib import Path

from staticjinja import Site
Expand All @@ -8,11 +9,15 @@
import sass


def load_page_data():
yaml = Path("./data").glob("*.yaml")
return {
file_path.stem: load(file_path.read_text(), Loader=Loader) for file_path in yaml
def load_page_data(template, /, *, base_url=None):
context_objects = Path("./data").glob("*.yaml")
context_mapping = {
file_path.stem: load(file_path.read_text(), Loader=Loader)
for file_path in context_objects
}
if base_url is not None:
context_mapping["base"]["base_url"] = base_url
return context_mapping


def clean_buildpath(output_dir):
Expand All @@ -25,12 +30,19 @@ def main():
except IndexError:
build_dir_str = "output"

try:
custom_domain_cli_arg = sys.argv[2]
except IndexError:
custom_domain_cli_arg = None

buildpath = Path(build_dir_str)
clean_buildpath(buildpath)

site = Site.make_site()
site.outpath = buildpath
site.contexts = [(".*.html", load_page_data)]

load_page_data_callable = partial(load_page_data, base_url=custom_domain_cli_arg)
site.contexts = [(".*.html", load_page_data_callable)]
# disable automatic reloading
site.render(use_reloader=False)

Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import nox

@nox.session
@nox.session(python=["3.11"]) # The python version should match the readthedocs configuration.
def build(session: nox.Session):
session.install(
"-r", "requirements.in",
Expand Down

0 comments on commit 8a5df32

Please sign in to comment.