Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Make the theme responsive#46

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JulienPalard merged 24 commits intopython:masterfromobulat:master
May 7, 2021
Merged

Conversation

obulat
Copy link
Contributor

I have been reading on my phone a lot lately, and was disappointed by the fact that I couldn't read python docs: the fonts are too small, and, if I try to zoom in, the text doesn't fit on the page, so I have to swipe to see the whole line.

This is my attempt to add responsiveness to python docs theme, fixing#30.

On screen widths smaller than 900 px, it:

  • adds a mobile navigation bar with a 'hamburger' menu button, Python version switcher and a search box.

  • adds a sliding menu that opens when 'hamburger' menu button is clicked. Menu contains language switching input and contents.

  • removes therelated bars

  • removes the sidebar.

Screenshot with menu closed:
Responsive  Menu closed Galaxy S5
Screenshot with menu open:
Responsive  Menu open Galaxy S5

Problems that need to be solved:

  • Normally, the mobile navigation bar should be placed in theheader block of the layout, but python.org layout completely overrides it, so I added it in the body_tag block. To solve this, I would need to add changes to that code.

  • I placed the switchers and other items on the menus as seemed logical to me, but feedback from the community is essential on this.

  • I added a javascript file to open/close sidebar in a separate file. I could also add it into the layout file, but ideally all js files should be combined and minified.

pradyunsg, NeilGirdhar, and pquentin reacted with heart emoji
Copy link
Contributor

@septatrixseptatrix left a comment

Choose a reason for hiding this comment

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

Overall a great idea and I would also really like a responsive theme though there seem to be some unrelated changes and implementation details which should be discussed

Comment on lines 2 to 22
document.addEventListener('DOMContentLoaded', function () {
const toggler = document.querySelector('.toggler');
const sideMenu = document.querySelector('.menu-wrapper');
const doc = document.querySelector('.document');
function closeMenu() {
sideMenu.classList.remove('open');
toggler.checked = false;
}
toggler.addEventListener('change', function (e) {
if (toggler.checked) {
sideMenu.classList.add('open');
} else {
closeMenu();
}
});
doc.addEventListener('click', function () {
if (toggler.checked) {
closeMenu();
}
})
})
Copy link
Contributor

Choose a reason for hiding this comment

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

By moving the checkbox up in the dom tree it may be possible to implement this using only javascript and make it more accessible for people without javascript

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I replaced the checkbox with a button. Is this better for people without javascript?

Copy link
Contributor

Choose a reason for hiding this comment

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

What I would have done is move the input as a checkbox directly next to the sidebar, reference it in the label via id and apply the styles based on whether the checkbox is checked or not. I may have time tomorrow to create a PR on your fork repo if you want to.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I have done it like this at first (checkbox input and applying styles based on :checked property). Then I was checking for accessibility and foundthis article which shows that a button as menu opener has some advantages regarding accessibility: namely, it is easier to set up keyboard handling. On the other hand, I just realized that people probably don't use keyboard for navigation on mobile, and it is more important to set up No-script solution than keyboard navigation on mobile.
Also, I looked at other documentation sites: readthedocs theme and VueJS docs, and their hamburger menu doesn't work without javascript.

Copy link
Contributor

Choose a reason for hiding this comment

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

In addition if you followthis guide you also get a working css only solution with added accesibility using javascript

@obulat
Copy link
ContributorAuthor

Thank you for your review,@septatrix !
I don't have a reliable internet connection at the moment, but will try to address your comments as soon as possible. Overall, I have tried to make the theme accessible as well as responsive, that's the reason for some label handling. Also, I tried to use only Vanilla javascript to make it easier to remove jquery dependency in the future.

I would also like to have your feedback on the content for the mobile version. For example, the top navbar on mobile: Do you think logo, version switcher and searchbox are what should be there, or do we need to add/ remove something?

Also, the relbar is completely removed, but I thought that it might be a good idea to add it at the bottom, without the searchbox, though.

- Remove unnecessary `show` call for searchbox.- Remove `box-sizing:border-box` for all elements.- Add `aria-label` to search input instead of visually-hiding labels for accessibility- Some style fixes
@JulienPalard
Copy link
Member

JulienPalard commentedJun 20, 2020
edited
Loading

Beware, i'm working on moving the switchers generation code to docsbuild scripts instead of cpython. Seepython/docsbuild-scripts#90

I did not think about switchers being located in different places, we have to check if there is something to fix either in docsbuild side or here.

As the switchers are no longer to be maintained in cpython, I was removing the placeholders and the switchers variable inpython/cpython#20969

I'm on my phone right know so I can't test it, but we need to agree on how to "communicate" to docsbuild the switchers places.

obulat and septatrix reacted with thumbs up emoji

@JulienPalard
Copy link
Member

JulienPalard commentedJun 21, 2020
edited
Loading

Hi@obulat!

Took the time to think about it, but beware, I'm particularily bad at HTML/JS:

  • python-docs-theme is not cpython specific, it can be used elsewhere, that's typically why the "This document is for an old version of Python" headeris in cpython and not in the theme.
  • Switchers arenot cpython specific: other documentations can be translated and have versions.
  • The classes.version_switcher_placeholder and.language_switcher_placeholder has always been in use and looks good to me.
  • Having multiple version placeholders may work, IIRC, jquery will properly create them all when I do$('.version_switcher_placeholder').html(version_select);

The currentswitchers.js,the one from docsbuild-scripts has two ways of working (see function create_placeholders_if_missing):

  • Either there's a '.version_switcher_placeholder' and it uses it (typically when cpython or the theme places it)
  • Either there's not, and it tries it best to find a place to create both placeholders (side by side), see the uglyprobable_places array (I may soon add a cleanercpython-language-and-version in front of it, but it may not be usefull if you handle it in the theme).

What about adding all needed placeholders in python-docs-theme, soswitchers.js from docsbuild-scripts could rely on them, instead of trying to inject HTML? In "mobile version" it currently injects them in HTML that is not rendered, so no switchers appear.

How to test with docsbuild-script locally:

$# In a clone of docsbuild-scripts$ mkdir -p www logs build_root$ python3 -m venv build_root/venv/$ build_root/venv/bin/python -m pip install -r requirements.txt$ build_root/venv/bin/python -m pip install path_to_your_python-docs-theme$ python3 ./build_docs.py --quick --build-root build_root --www-root www --log-directory logs --group$(id -g) --skip-cache-invalidation --language en --branch master

(Currently testing it and wow, that's really nice, thanks a lot for working on this topic!)

@obulat
Copy link
ContributorAuthor

Hi,@julien, thank you for your comments, that's really helpful!

I will try to look into it as soon as I have time.

JulienPalard reacted with thumbs up emojijulien reacted with eyes emoji

@septatrix
Copy link
Contributor

I think a problem which should be tackled first is overflowing stuff liketables, alldt for definitions as well ascode segments inside the docs. These are for the most part not broken an lead to a wider page than intended. Together with the addition of the<meta name="viewport" ...> tag this will already solve most problems. This way no major design changes would be necessary as the sidebar should actually also work great on mobile devices (maybe make it a few pixels wider). The problem with the header/footer wrapping badly due to its floating nature already happens for me at around 1200px width.

- Menu is opened/closed using only css (invisible checkbox), works without js enabled- Accessibility added using javascript
@obulat
Copy link
ContributorAuthor

I think a problem which should be tackled first is overflowing stuff liketables, alldt for definitions as well ascode segments inside the docs. These are for the most part not broken an lead to a wider page than intended. Together with the addition of the<meta name="viewport" ...> tag this will already solve most problems. This way no major design changes would be necessary as the sidebar should actually also work great on mobile devices (maybe make it a few pixels wider). The problem with the header/footer wrapping badly due to its floating nature already happens for me at around 1200px width.

I've added wrappingtables in adiv that can be horizontally scrolled: this is the solution used in readthedocs.dt andcode segments are already horizontally scrollable.

z-index: 1;
}
.mobile-nav * {
box-sizing: border-box;
Copy link
Contributor

Choose a reason for hiding this comment

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

If possibly I would stay with the sphinx default of not modifying the box-sizing property

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I tried removing it, but I couldn't get the searchbox to fit the screen on all the different sizes: flexbox and padding and border incontent-box sizing model are too complex. I don't think adding a different box-sizing property should be a problem because the new box-sizing applies only to the.mobile-nav part.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, I don't see any reason to avoid doing this, as long as whoever works on this theme finds that model easier to work with. There are variants of normalise.css that set this on the entire page, so setting this for a whole bunch of elements, is A-OK in my opinion.

@pradyunsg
Copy link
Member

Wheee! This is amazing. Is there anything I can do to help move this forward? :)

@obulat
Copy link
ContributorAuthor

Hi, should I close this issue due to the new theme added inpypa/pip#9012 ?

@pradyunsg
Copy link
Member

@obulat No no. I don’t imagine docs.python.org would be changing to that theme anytime soon, and this PR is a pretty great improvement over status quo.

obulat, septatrix, and JulienPalard reacted with thumbs up emoji

@septatrix
Copy link
Contributor

And even if the theme were to change there may still be other projects using this theme

@obulat
Copy link
ContributorAuthor

What about adding all needed placeholders in python-docs-theme, soswitchers.js from docsbuild-scripts could rely on them, instead of trying to inject HTML? In "mobile version" it currently injects them in HTML that is not rendered, so no switchers appear.

Hi,@JulienPalard ,

I'm on Windows, so originally I couldn't test thedocsbuild-scripts steps because they wouldn't run. Now, I tried running them on my Ubuntu (Windows Subsystem for Linux), but I couldn't get my local version of the theme to apply.

However, I did add empty placeholder divs:.version_switcher_placeholder in the top navbar, and.language_switcher_placeholder in the left menu.
Could you please test it?

@obulat
Copy link
ContributorAuthor

I'm sorry it took me so long to get back to implementing the requested changes.
@pradyunsg , thank you for your comments!

The index page still doesn't look too good, with the main reason being that the layout used for contents is a table, which doesn't look good on a small screen. I think we should convert it into a two-column layout that can be converted into a one-column layout on smaller screens. However, I would say it is a to-do for another PR.

pradyunsg reacted with heart emoji

@JulienPalard
Copy link
Member

I'm on Windows, so originally I couldn't test thedocsbuild-scripts steps because they wouldn't run.

There's no Windows support on docsbuild-scripts, and I don't except to add it anytime.

Now, I tried running them on my Ubuntu (Windows Subsystem for Linux), but I couldn't get my local version of the theme to apply.

This is really strange, can you open an issue on docsbuild-script with the steps you followed so I can try reproduce and we fix this? I often build the docs locally (on Debian), and have no theme issues.

@JulienPalard
Copy link
Member

@obulat I was able to build a local version, I had to patch docsbuild-scripts (hardening a regex detecting the version part in the URL in case the URL contains an IP like 0.0.0.0 ...).

It works: it gets replaced \o/ but only on mobile, as the placeholder only exist for mobile.

@obulat
Copy link
ContributorAuthor

There's no Windows support on docsbuild-scripts, and I don't except to add it anytime.

I completely understand, just wanted to add this bit of information for context.

This is really strange, can you open an issue on docsbuild-script with the steps you followed so I can try reproduce and we fix this? I often build the docs locally (on Debian), and have no theme issues.

I will try to do that as soon as I can.

@obulat
Copy link
ContributorAuthor

@obulat I was able to build a local version, I had to patch docsbuild-scripts (hardening a regex detecting the version part in the URL in case the URL contains an IP like 0.0.0.0 ...).

It works: it gets replaced \o/ but only on mobile, as the placeholder only exist for mobile.

As this PR is for the mobile version, I did not touch the placeholders for the desktop version. I could add them here, or in a new PR.

@JulienPalard
Copy link
Member

As this PR is for the mobile version, I did not touch the placeholders for the desktop version. I could add them here, or in a new PR.

I can understand, but this is a bit dangerous: if there's a release between your two PRs, language and version switchers will disaperar on desktop (as paceholders are found on the new mobile part, my code don't try to add them on the desktop part).

I mean, in switchers.js I have two branches : either the placeholders are found and I use them, or they are not found and I create them, so if they're found, they're not created.

@obulat
Copy link
ContributorAuthor

I can understand, but this is a bit dangerous: if there's a release between your two PRs, language and version switchers will disappear on desktop (as placeholders are found on the new mobile part, my code don't try to add them on the desktop part).

I didn't realize that. I tend to include too much in my PRs, so I was trying to improve myself 😄

I added the placeholders.

@pradyunsg
Copy link
Member

The plan sounds good to me! And, as I'm probably over-stating now, we can iterate too! :)

@@ -85,7 +85,10 @@ <h3>{{ _('Navigation') }}</h3>
<span></span>
</label>
<nav class="nav-content" role="navigation">
<img src="{{ pathto('_static/' + 'py.svg', 1) }}" alt="Logo"/>
<a href="{{ pathto('index') }}">
Copy link
Member

Choose a reason for hiding this comment

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

pathto(master_doc) would be more appropriate here?

Copy link
Member

Choose a reason for hiding this comment

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

Or does CPython documentation use contents for the toctree?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Thank you for such a quick review! :) I know what I added doesn't work for sure. Let me try pathto(master_doc).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I need help!
I don't know how to add the correct link to thedocs.python.org/3.9/.
In line 88 in layout.html I added<a href="{{ pathto(theme_root_url) }}", and it createsfile:///.../doc-html(3)/3.9/https://www.python.org/.html

Copy link
Member

Choose a reason for hiding this comment

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

Don't wrap it in pathto, just{{ theme_root_url }} is enough.

That should fix it. :)

Copy link
Member

@pradyunsgpradyunsgMay 5, 2021
edited
Loading

Choose a reason for hiding this comment

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

In other words, that is behaviour I'd expect and I thought that's what you wanted?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I guess I was confusing the two kind of links (to the docs home and the language/framework home). On the sites I used a lot lately (eg Vue.js) the style of the framework home page and the style of the documentation homepage are the same. And it feels like I just go to the documentation home, not the general home, when I click on the logo.

But you are right, now we have the correct behavior, linking to python.org.

We still don't have a way of going to the documentation homepage,docs.python.org/3 from other pages on mobile. Is it necessary to add it, and add it in this PR specifically?

pradyunsg reacted with thumbs up emoji
Copy link
Member

@pradyunsgpradyunsgMay 5, 2021
edited
Loading

Choose a reason for hiding this comment

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

If you want to have a link to the documentation homepage, that'd be{{ pathto(master_doc) }} or{{ pathto("index") }}. No need for a |e on either of them.

obulat reacted with thumbs up emoji
Copy link
Member

@pradyunsgpradyunsgMay 5, 2021
edited
Loading

Choose a reason for hiding this comment

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

Honestly, this feels like something we can do in a follow up PR.

I'd really like to push for getting this landed soon, so that we can start moving other things forward without needing to come back and update this.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Please, let me know if I need to change anything? I would be happy to get this landed soon, too!

@JulienPalard
Copy link
Member

LGTM.@pradyunsg if it's OK for you too, I'm ok for a merge :)

willingc and pradyunsg reacted with heart emoji

@willingc
Copy link
Contributor

Way to go@obulat 🎉 🐍! Thanks for the great teamwork@JulienPalard and@pradyunsg. Happy to see this merged soon 👍🏼

pradyunsg reacted with heart emoji

@obulat
Copy link
ContributorAuthor

Thank you everyone! I'm really excited for this change!

Copy link
Member

@pradyunsgpradyunsg left a comment

Choose a reason for hiding this comment

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

🚀

JulienPalard and obulat reacted with rocket emoji
@JulienPalardJulienPalard merged commit8449732 intopython:masterMay 7, 2021
@JulienPalard
Copy link
Member

Thanksa lot@obulat, I hope this can go to production soon.@willingc do you know the release process?

I don't have the upload rights to pypi/p/python-docs-theme.

obulat reacted with hooray emoji

@willingc
Copy link
Contributor

I don't@JulienPalard, but I can look into it tomorrow.

@birkenfeld
Copy link
Member

Thanks also from me - when I originally put together this theme I hadn't even expected it to live so long :D

obulat reacted with rocket emoji

@willingc
Copy link
Contributor

@Mariatta@ncoghlan@theacodes If one of you can deploy this awesome update or give@JulienPalard or me privileges that would be great. Would love to see@obulat's work in production 🎉

@birkenfeld Thank you for all that you have done for docs over the years. You rock. 🎉

JulienPalard reacted with thumbs up emojiastrojuanlu, obulat, and pradyunsg reacted with hooray emojibirkenfeld and pradyunsg reacted with heart emoji

@theacodes
Copy link
Collaborator

@willingc you now have permissions on PyPI ✨

willingc reacted with hooray emojipradyunsg reacted with rocket emoji

@septatrix
Copy link
Contributor

If there are already so many people taking a look at this right now I would like to mention the dark theme PR which also is ready for review

@willingc
Copy link
Contributor

@septatrix I just saw this now. After the dark theme lands we can do a dot release to get that in.

miketheman added a commit to miketheman/python-docs-theme that referenced this pull requestJul 27, 2023
The CSS in the base template was updated to include this directive in #7695and released in sphinx v3.1.0.The original implementation was inpython#46, prior to the basic themeincluding it, and now we have the same meta tag duplicated.Remove the block, and reduce the duplication.Signed-off-by: Mike Fiedler <miketheman@gmail.com>
@hugovkhugovk mentioned this pull requestJan 28, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@septatrixseptatrixseptatrix requested changes

@JulienPalardJulienPalardJulienPalard approved these changes

@willingcwillingcwillingc approved these changes

@pradyunsgpradyunsgpradyunsg approved these changes

@FGuilletFGuilletFGuillet approved these changes

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

10 participants
@obulat@JulienPalard@septatrix@pradyunsg@willingc@Mariatta@birkenfeld@theacodes@FGuillet@the-knights-who-say-ni

[8]ページ先頭

©2009-2025 Movatter.jp