-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Docs: Add documentation for CustomScript addon #12623
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
Merged
+61
−0
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6db7b8e
Initial plan
Copilot 9ed281a
Add documentation for CustomScript addon feature
Copilot 013e2bf
Improve clarity in CustomScript documentation
Copilot 2abf4e4
Address PR feedback: add Custom Script to features list and update co…
Copilot 6d3895e
Move Custom Script section to separate file custom-script.rst
Copilot 00cecf6
Add file to the index
humitos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| Custom script | ||
| ============= | ||
|
|
||
| The Custom Script addon allows you to inject a custom JavaScript file into your documentation at serve time. | ||
| This enables you to modify or enhance frozen documentation without rebuilding it. | ||
|
|
||
| .. note:: | ||
|
|
||
| The Custom Script addon is not currently exposed in the user interface. | ||
| If you would like to use this feature, | ||
| please :doc:`contact support </support>`. | ||
|
|
||
| Using custom scripts | ||
| -------------------- | ||
|
|
||
| This addon allows specifying a URL to a JavaScript file that will be injected into all pages of your documentation. | ||
| The script can be hosted on Read the Docs itself (as a relative URL) or on an external server (as an absolute URL). | ||
|
|
||
| Common use cases for custom scripts include: | ||
|
|
||
| * Fixing bugs or adding features to frozen documentation | ||
| * Injecting analytics or tracking code | ||
| * Customizing the appearance or behavior of specific documentation versions | ||
|
|
||
| Accessing Addons data from your script | ||
| -------------------------------------- | ||
|
|
||
| Custom scripts are loaded asynchronously after the initial page load, | ||
| which means the ``readthedocs-addons-data-ready`` event has already been fired by the time your script executes. | ||
| To access the Addons data from your custom script, | ||
| check the ``window.ReadTheDocsEventData`` object first, | ||
| then subscribe to the event for future updates (for example, when the URL changes in a single-page application): | ||
|
|
||
| .. code-block:: javascript | ||
|
|
||
| function handleReadTheDocsData(data) { | ||
| // Access the Addons data here | ||
| console.log("Project slug:", data.projects.current.slug); | ||
|
|
||
| // You can filter by version to apply changes selectively | ||
| if (data.versions.current.slug === "v3.0") { | ||
| // Do something specific for version v3.0 | ||
| } | ||
| } | ||
|
|
||
| // The event "readthedocs-addons-data-ready" has been already fired when this script is run. | ||
| // We need to check for `window.ReadTheDocsEventData` first, and if it's available | ||
| // use that data to call the handler. | ||
| if (window.ReadTheDocsEventData !== undefined) { | ||
| handleReadTheDocsData(window.ReadTheDocsEventData.data()); | ||
| } | ||
|
|
||
| // After that, we subscribe to the Read the Docs Addons event to access data | ||
| // on future dispatchs (e.g. when a URL changes on a SPA) | ||
| document.addEventListener("readthedocs-addons-data-ready", function (event) { | ||
| handleReadTheDocsData(event.detail.data()); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,7 @@ Read the Docs: documentation simplified | |
| /server-side-search/index | ||
| /server-side-search/syntax | ||
| /flyout-menu | ||
| /custom-script | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should go in another TOC -- maintaining I'd say.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! I will move it there. |
||
|
|
||
| .. toctree:: | ||
| :maxdepth: 2 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.