Metadata-Version: 2.4
Name: sphinx-live-refresh
Version: 0.1.0
Summary: Quietly reload open Sphinx and Jupyter Book HTML pages when a new build is published.
Author: NB-TUDelft, K.Zabłocki (Zamkorus)
Maintainer: NB-TUDelft, K.Zabłocki (Zamkorus), AsapLoso
License-Expression: MIT
Project-URL: Homepage, https://github.com/NB-TUDelft/sphinx-live-refresh
Project-URL: Repository, https://github.com/NB-TUDelft/sphinx-live-refresh
Project-URL: Issues, https://github.com/NB-TUDelft/sphinx-live-refresh/issues
Project-URL: Changelog, https://github.com/NB-TUDelft/sphinx-live-refresh/releases
Keywords: sphinx,jupyter-book,live-refresh,auto-reload,documentation
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Sphinx
Classifier: Framework :: Sphinx :: Extension
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Documentation :: Sphinx
Classifier: Topic :: Software Development :: Documentation
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: sphinx>=7
Dynamic: license-file

# sphinx-live-refresh

Quietly reload open Sphinx and Jupyter Book HTML pages when a new build is published, then scroll back to where the reader was.

Unlike local development tools such as `sphinx-autobuild`, this extension works on **published static sites** (such as GitHub Pages) with no server-side support — useful when pushing fixes during a lab or lecture while students already have the manual open.

## How it works

- Each successful web HTML build writes a tiny `_static/live_refresh.json` containing a unique build ID and adds `live_refresh_config.js` and `live_refresh.js` to every page.
- An open page polls `_static/live_refresh.json` while visible (skipped for local `file://` opens and offline builders such as `epub`).
- The first response establishes the build the page came from; a different ID later means a new build is live.
- A visible tab waits until the reader has been idle for a few seconds, is not typing in a form field, has no text selected, and no busy selector matches (open `<dialog>` elements or active Thebe live-code cells), then saves the scroll position and reloads.
- A hidden tab reloads immediately, and once reloaded the page scrolls back to where the reader was.

## Install

From PyPI:

```bash
uv add sphinx-live-refresh
```

```bash
pip install sphinx-live-refresh
```

From the `NB_TUDelft` channel on anaconda.org (include `conda-forge` for `sphinx`):

```bash
conda install -c NB_TUDelft -c conda-forge sphinx-live-refresh
```

To follow the unreleased `main` branch instead of a release, install from Git:

```bash
uv add "sphinx-live-refresh @ git+https://github.com/NB-TUDelft/sphinx-live-refresh.git"
```

## Enable

In a Jupyter Book `_config.yml`:

```yaml
sphinx:
  extra_extensions:
    - sphinx_live_refresh
```

In a plain Sphinx `conf.py`:

```python
extensions = ["sphinx_live_refresh"]
```

No further configuration is required for the defaults.

## Configure

All options are optional and use the `live_refresh_` prefix:

| Option | Default | Meaning |
| --- | --- | --- |
| `live_refresh_enabled` | `True` | Set to `False` to omit the script and manifest (e.g. for local builds). |
| `live_refresh_poll_interval` | `60` | Seconds between checks while the page is visible (`1`–`86400`). |
| `live_refresh_quiet_period` | `10` | Seconds of reader inactivity before a visible tab reloads (`0`–`86400`). |
| `live_refresh_busy_selectors` | `("dialog[open]", ".thebe-cell", ".thebelab-cell", ".thebe-controls")` | CSS selectors that defer reloading while visible. Set to `[]` to disable selector checks. |
| `live_refresh_build_id` | `None` | Explicit build ID written to `_static/live_refresh.json` (defaults to a nanosecond timestamp per build). |

Example in a Jupyter Book `_config.yml`:

```yaml
sphinx:
  extra_extensions:
    - sphinx_live_refresh
  config:
    live_refresh_poll_interval: 30
    live_refresh_quiet_period: 15
    live_refresh_busy_selectors:
      - "dialog[open]"
      - ".thebe-cell"
      - ".thebelab-cell"
      - ".thebe-controls"
      - ".my-interactive-widget"
```

Example in a plain Sphinx `conf.py`:

```python
import os

extensions = ["sphinx_live_refresh"]
live_refresh_enabled = bool(os.environ.get("CI"))
live_refresh_build_id = os.environ.get("GITHUB_SHA") or None
```

## Releasing

Maintainers: see [RELEASING.md](RELEASING.md). In short, bump the version in `pyproject.toml`, `src/sphinx_live_refresh/__init__.py`, and `uv.lock`, commit, then push a `vX.Y.Z` tag — GitHub Actions publishes to PyPI and anaconda.org from the tag.

## License

MIT — see [LICENSE](LICENSE).
