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

Generate list instead of div items in sidebar #93780

Merged
merged 2 commits into from
Feb 18, 2022

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Feb 8, 2022

Fixes #92986.

Surprisingly, we didn't have much CSS for this...

Demo.

r? @jsha

@rust-highfive
Copy link
Collaborator

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez,@Folyd,@jsha

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Feb 8, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 8, 2022
@bors
Copy link
Contributor

bors commented Feb 9, 2022

☔ The latest upstream changes (presumably #93795) made this pull request unmergeable. Please resolve the merge conflicts.

@jsha
Copy link
Contributor

jsha commented Feb 9, 2022 via email

@GuillaumeGomez
Copy link
Member Author

Sorry, forgot to push it... Here you go: https://rustdoc.crud.net/imperio/links-in-sidebar/std/index.html

Copy link
Contributor

@jsha jsha left a comment

Choose a reason for hiding this comment

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

Generally looks great, thanks for working on this!

I mentioned in the review, but I think each portion of the sidebar that has a heading should get its own <div class="block">. That would make the HTML structure more consistent, and also simplify the styling. If we want to get fancy, the <section> element actually seems like a nice semantic replacement for <div class="block">. But I don't feel strongly about whether we use it or not.

By the way, I notice that wherever we use <div class="block">, there's a second class, like block items, block struct etc. Do we ever actually use that second class? Can we get rid of it?

white-space: nowrap;
}

.sidebar-elems .block.items ul:not(last-child),
Copy link
Contributor

Choose a reason for hiding this comment

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

It's usually best to avoid the :not() selector.

But also, I'm surprised you needed to add this. The existing .block { margin-bottom: 2em } rule should have been enough.

Looking at the HTML, it looks like the whole first part of the sidebar (items on this page) is contained in a single .block. But down below, for items in this module, there's a separate block for each heading. So the structure is like:

<div class="block <foo>">
  <h3>...</h3>
  <ul>...</ul>
</div>

We should make the structure up above the same, so there is a separate block for each heading plus the <ul> underneath it. Then you won't need the extra CSS rule here, and the format of the HTML will be more consistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's what I wanted to do at first but I didn't know how to make the different between item's items and the rest. Maybe using <section> will do the trick.

@@ -504,7 +500,11 @@ h2.location a {
margin: 0;
}

.sidebar-links,
.sidebar-elems .block.items a {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be better:

Suggested change
.sidebar-elems .block.items a {
.sidebar-elems li {

The rule doesn't need to be specific to .block.items. For instance, it should apply to the "items in this module" section too. Also: selecting on li instead of a is a nice easy way to say "Headings (h2, h3) can wrap, even when they contain an <a> since we generated them and we know they are of a reasonable length. However, list items are Rust item names; they're out of our control, sometimes quite long, and wrap weirdly. Truncate them rather than wrap."

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently it's not the case, which is why I only applied it on these items specifically. But if you want, I can do it for all.

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Feb 10, 2022

Now all items in the sidebar are rendered the same way (wrapped in ul itself in a div.block).

I also applied the word-wrap for all li elems in the sidebar making this change:

In the current nightly:
Screenshot from 2022-02-10 20-18-54

With this PR:
Screenshot from 2022-02-10 20-18-52

I updated the demo too.

@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@jsha jsha left a comment

Choose a reason for hiding this comment

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

I love the refactoring to add print_sidebar_block. That's a nice abstraction. Rather than taking a callback, I think it should take impl Iterator<Item = &str>. That would be simpler, and AFAICT all of the inputs can be expressed as iterators.

Comment on lines 2497 to 2550
"<section class=\"items\">\
<div class=\"block\">\
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking that <section> (no class) would replace <div class=\"block\">. Then the relevant CSS selectors would be .sidebar section.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I see. Even better then!

@GuillaumeGomez
Copy link
Member Author

Applied your suggestions! I also updated the demo.

@jsha
Copy link
Contributor

jsha commented Feb 17, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 17, 2022

📌 Commit 0d928b6 has been approved by jsha

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 17, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 17, 2022
…askrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#93337 (Update tracking issue numbers for inline assembly sub-features)
 - rust-lang#93758 (Improve comments about type folding/visiting.)
 - rust-lang#93780 (Generate list instead of div items in sidebar)
 - rust-lang#93976 (Add MAIN_SEPARATOR_STR)
 - rust-lang#94011 (Even more let_else adoptions)
 - rust-lang#94041 (Add a `try_collect()` helper method to `Iterator`)
 - rust-lang#94043 (Fix ICE when using Box<T, A> with pointer sized A)
 - rust-lang#94082 (Remove CFG_PLATFORM)
 - rust-lang#94085 (Clippy: Don't lint `needless_borrow` in method receiver positions)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6a2b612 into rust-lang:master Feb 18, 2022
@rustbot rustbot added this to the 1.60.0 milestone Feb 18, 2022
@GuillaumeGomez GuillaumeGomez deleted the links-in-sidebar branch February 18, 2022 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rustdoc: consistentize sidebar HTML generation
6 participants