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

nixos-render-docs: make examples collapsible by default #301152

Merged
merged 1 commit into from
Apr 4, 2024

Conversation

DanielSidhion
Copy link
Member

Description of changes

During work on #297654 it got a bit annoying IMO to always see examples fully shown by default on the manuals. This is especially annoying when we want to add an example somewhere in the middle of some explanation, when there's no better place to move the example to (and then link to it from the text).

This PR wraps each example under a <details> tag which makes every example collapsible, and each one is collapsed by default. It also adds a bit of CSS to make it more usable.

An example of what it looks like on my browser:
20240402T214614
And after expanding an example:
20240402T214621

The CSS is up for discussion. I tried with and without the borders after expanding, but eventually settled on borders because some examples are kinda large, and the borders help determine when an example ends. I could definitely use help improving the visual though.

Things I tested:

  • Examples with and without an id attached to them works.
  • Links to an example still work.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

Copy link
Contributor

@hsjobeki hsjobeki left a comment

Choose a reason for hiding this comment

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

Looks good to me. Seems we have highly specific css.

@@ -347,6 +347,22 @@ div.appendix div.example {
margin-top: 1.5em;
}

div.book div.example details,
div.appendix div.example details {
Copy link
Contributor

Choose a reason for hiding this comment

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

Your CSS assumes a very specific HTML structure. If the HTML changes, such as adding another parent div this will break.
Id suggest '.example details'
which targets all details with a parent of class .example
this would allow other parents as well. making it more resistent to potential future changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer to keep the specific CSS here - it's only used with the output of nrd, and we control the HTML structure there. It's expected that changes to nrd will be at least rendered so we can glance over the output, and if the CSS needs to be adapted (such as in this case), then we'll just change the CSS as well.

To explain why I'm taking this stance: this CSS file has a few rules that conflict on certain elements, and we rely on the more specific rule overriding the value of the less specific one.
As an exercise, I tried removing all the div.book and div.appendix specifiers from all the other rules as well, and some things got messed up.
I prefer keeping the specific rules because that's how the rest of the CSS is laid out, so it avoids subtle things from breaking if someone decides to change some other less-specific rule.

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

(reviewed in the docs team)

Looking good, this is awesome, let's merge!

@infinisil infinisil merged commit 60e0053 into NixOS:master Apr 4, 2024
28 checks passed
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-04-04-documentation-team-meeting-notes-117/42754/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants