Use environment variable to control indexing of rendered docs #9455

Closed
opened 2025-12-29 20:50:07 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Apr 8, 2024).

Originally assigned to: @jeremystretch on GitHub.

Proposed Changes

When the NetBox documentation is rendered using mkdocs, we ensure that indexing by search engines is disabled unless it has been built for ReadTheDocs. This is done to avoid search engines accidentally caching the local documentation served by publicly-exposed NetBox deployments in the wild, which taints search results.

This is currently accomplished by checking that the page.canonical_url context variable is set to docs.netbox.dev:

b7668fbfc3/docs/_theme/main.html (L6-L8)

This approach is taken because ReadTheDocs currently does not support the use of environment variables within mkdocs configuration files. However, per this recent blog post, support for referencing environment variables will be introduced on April 15. (See also this comment.)

I've opened this issue to track the switch to using an environment variable instead of the context variable (essentially reverting efd86526f41ca6e4c4eba44fd508ca96811ef496).

Justification

The environment approach is more flexible as it more customizable and does not rely on an exact string match.

Originally created by @jeremystretch on GitHub (Apr 8, 2024). Originally assigned to: @jeremystretch on GitHub. ### Proposed Changes When the NetBox documentation is rendered using `mkdocs`, we ensure that indexing by search engines is disabled unless it has been built for ReadTheDocs. This is done to avoid search engines accidentally caching the local documentation served by publicly-exposed NetBox deployments in the wild, which taints search results. This is currently accomplished by checking that the `page.canonical_url` context variable is set to `docs.netbox.dev`: https://github.com/netbox-community/netbox/blob/b7668fbfc3a81abf2c6a8ace98047647fd9244c9/docs/_theme/main.html#L6-L8 This approach is taken because ReadTheDocs currently does not support the use of environment variables within `mkdocs` configuration files. However, per [this recent blog post](https://about.readthedocs.com/blog/2024/03/mkdocs-yaml-manipulation/), support for referencing environment variables will be introduced on April 15. (See also [this comment](https://github.com/readthedocs/readthedocs.org/issues/8529#issuecomment-2042328766).) I've opened this issue to track the switch to using an environment variable instead of the context variable (essentially reverting efd86526f41ca6e4c4eba44fd508ca96811ef496). ### Justification The environment approach is more flexible as it more customizable and does not rely on an exact string match.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 20:50:07 +01:00
adam closed this issue 2025-12-29 20:50:07 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9455