Skip to content
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

DOC: dynamically create a version pull-down using javascript #46652

Closed
wants to merge 3 commits into from

Conversation

mattip
Copy link
Collaborator

@mattip mattip commented Oct 21, 2020

Enhancement to create a version pulldown rather than a link to a static list of versions.html

  • The version is now passed to sphinx from the environment, so the post-processing to mangle the version is no longer needed
  • The layout template has been changed
    • The javascript scripts are loaded in the header, this should be backported to the upstream pytorch_sphinx_theme repo since now the loading stanza appears twice on the page :(. I needed this to activate the new javascript function as the page loads.
    • A new snippet of javascript builds a ul list of versions on document loading (provides consistency across documentation versions)
      • The snippet will try to match the current document to the one from the other versions. If there is a match, switching versions will keep you at the same page.
    • The version list is now below the search bar.

I could not get the page existence check to work asynchronously, so page loading time takes a hit. Is the UX improvement worth it? I was basing this off the warning in the NumPy docs when you view older documentation, this is a page with no parallel in the latest version, so the message will pre-populate a search qeury (source code here). maybe I missed something? In any case, the NumPy script only needs to check for the latest page, my adaptaion scans all the versions.

Help here would be welcome from people fluent in web front-end programming.

open_list = '<li id="current">'
}
}
const pathPattern = /docs\/(build\/html|stable|master|[0-9.rc]+)(.*)/;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whether you build locally or deploy to pytorch/pytorch.github.io, the document URL will look like

file:///home/user/pytorch/docs/build/html/generated/torch.nn.parameter.Parameter.html
or
https://pytorch.org/docs/1.6.0/generated/torch.nn.parameter.Parameter.html

So the docs part is a consistent anchor, then either build/html or one of the versions (stable', master, 1.6.0` etc), then the actual document name we are interested in.

document.write(open_list);
document.write('<a id=ID href="URL">VERSION</a> </li>\n'
.replace('VERSION', label)
.replace('URL', url));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get this to work with async: true and then rewriting the item.href.

<script type="text/javascript" data-url_root="{{ pathto('', 1) }}" src="{{ pathto('_static/docversions.js', 1) }}"></script>
{{ super() }}
{% endblock %}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This si the bit that should be upstreamed to the theme (without the _static/docversions.js). Is there a reason they have it so late in the template there? Connected to {% if not embedded %} ?

{% endif %}
{% endif %}
{% endblock %}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block overrides the original sidebartitle block

@zou3519 zou3519 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Oct 21, 2020
@zou3519 zou3519 self-requested a review October 21, 2020 14:16
@dr-ci
Copy link

dr-ci bot commented Oct 22, 2020

🔗 Helpful links

💊 CI failures summary and remediations

As of commit 766bafb (more details on the Dr. CI page):


Commit 766bafb was recently pushed. Waiting for builds...


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@mattip
Copy link
Collaborator Author

mattip commented Oct 22, 2020

Now the linking is working properly. This page is available in all versions, this page is only available in versions 1.6.0 and higher.

@facebook-github-bot
Copy link
Contributor

Hi @mattip!

Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but we do not have a signature on file.

In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

Copy link
Contributor

@brianjo brianjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the preview for this and I think it's good. Would love to see this added to release going forward, and master. (We don't need to rebuild previous versions.)

Copy link
Member

@seemethere seemethere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks mostly good, just one minor nit

docs/source/_static/docversions.js Outdated Show resolved Hide resolved
Co-authored-by: Eli Uriegas <1700823+seemethere@users.noreply.github.com>
@brianjo brianjo marked this pull request as draft November 11, 2020 21:50
@brianjo
Copy link
Contributor

brianjo commented Nov 11, 2020

Converted to Draft, @ranman is going to work on some changes.

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@pytorchbot
Copy link
Collaborator

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
Stale pull requests will automatically be closed 30 days after being marked Stale

@mattip
Copy link
Collaborator Author

mattip commented Apr 12, 2022

This was mostly a proof-of-concept. Closing. At some point, the pytorch doc team may want to look at how the pydata theme implemented a version pulldown.

@mattip mattip closed this Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed open source Stale triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants