-
Notifications
You must be signed in to change notification settings - Fork 27
Add option to disable TryExamples without rebuilding docs #118
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
Conversation
To make thinks a bit more automatic, I would take a peak at the URL and look at wether it contains At least the |
} | ||
} | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also you have a mix of tabs and spaces :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha. I use Emacs and for languages I use regularly, I have it set up to handle the indentation automatically. I guess the out of the box Javascript mode isn’t doing that properly. I’ll look into installing proper tooling.
Having it be a json with a list of url patterns sounds like a good solution. |
Thanks @Carreau! I've updated it to check for a json file Another thought I had is that it would be useful to be able to specify a default |
I've deployed the docs at https://steppi.github.io/scipy with jupyterlite-sphinx pinned to this PR branch and added an ignore file https://github.com/steppi/scipy/blob/gh-pages/.try_examples_ignore.json, which disables all An example of a An example of a non- |
- might want to add more options later
- sorry, really need to look into configuring emacs properly
I've changed |
From a discussion, maybe we should have a "force-enable" function in the browser javascript console to force-enable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Miscelaneous comments.
docs/directives/try_examples.md
Outdated
`TryExamples` buttons will be hidden in files matching at least one of these patterns, | ||
effectively disabling the interactive documentation. In the provided example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want those to match files, or final URLs ?
.then(response => { | ||
if (!response.ok) { | ||
if (response.status === 404) { | ||
// try examples ignore file is not present. | ||
return null; | ||
} | ||
throw new Error(`Error fetching ${ignoreFilePath}`); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
if (!data) { | ||
return; | ||
} | ||
// Disable interactive examples if file matches one of the ignore patterns | ||
// by hiding try_examples_buttons. | ||
const regexPatterns = data.ignore_patterns; | ||
for (let pattern of regexPatterns) { | ||
let regex = new RegExp(pattern); | ||
if (regex.test(currentPagePath)) { | ||
var buttons = document.getElementsByClassName('try_examples_button'); | ||
for (var i = 0; i < buttons.length; i++) { | ||
buttons[i].classList.add('hidden'); | ||
} | ||
break; | ||
} | ||
} | ||
}) | ||
.catch(error => { | ||
console.error(error); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I talk to some local colleagues, and they told that most recent browser support top level await, so I think we canlater refactor into clearer code and avoid promises.
"<script>" | ||
'document.addEventListener("DOMContentLoaded", function() {' | ||
f'window.loadTryExamplesConfig("{config_path}","{docname}");' | ||
"});" | ||
"</script>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want the regex to match urls, that way if say on readthedocs we can have only /stable/
and /latest/
to show JupyterLight buttons, but not older version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, true. Mix up on my part. I didn't consider that we'd have two sets of deployed docs with different doc roots one at base_url + '/stable'
and the other at base_url + '/latest'
. I was thinking of the case where /
is the doc root, and it has subfolders /stable
and /latest
, which isn't how things would typically work.
Co-authored-by: M Bussonnier <[email protected]>
@Carreau, I've updated this to match url pathnames instead of sphinx docnames; use async/await instead of promises, and have added a function to toggle the visibility of the buttons for use from the console. |
Thanks, I think we should just merge and iterate, to see how it goes. |
Thank you both! |
Thanks @Carreau! I'll work on implementing your other suggestions today. |
This PR makes it so if a file entitled
.disable_try_examples
is added to the root level of the deployed documentation's build directory, "try examples" buttons will be hidden at page load time, effectively disabling interactive examples without requiring a documentation rebuild.A Javascript function checks at page load for the presence of the file, and if so, hides the buttons.
In scipy/scipy#19729 (comment), @rgommers noted that it would be good to be able to disable the interactive examples without requiring a rebuild of the documentation. This is particularly helpful for SciPy with its long documentation build and deployment times.