Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Learn to customize the rust-docs page #12

Open
kianenigma opened this issue May 7, 2023 · 5 comments
Open

Learn to customize the rust-docs page #12

kianenigma opened this issue May 7, 2023 · 5 comments
Labels
generalist Issue requires technical knowledge, but not deeply. infra issue does not require specific knowledge of the content, and is mainly about the system.

Comments

@kianenigma
Copy link
Collaborator

kianenigma commented May 7, 2023

So that we can hack it a bit to look more custom made.

Also, there are a few hacks that if we find answers to, we can use:

  1. rename pallet struct in #[cfg(doc)] polkadot-sdk#191
  2. Make it show tests, examples, and so on
  3. Easier distinction between types that are storage and not.
  4. Easier distinction between enums and struct that are part of pallet macros and those that are not.
  5. Easier distinction between functions that are getters.
  6. Easier distinction between functions that are dispatchables.

Some of these are being handled in an https://github.com/paritytech/substrate/tree/kiz-improve-fast-unstake-dcos, but in hacky ways.

Some ideas from GPT-4:

Rustdoc is a tool that generates documentation for Rust projects from doc-comments within the source code. While the default rendering is sufficient for most use-cases, you might want to customize it to better suit your needs or preferences. Here are a few hacks to tweak the rendering of Rustdocs:

Custom CSS:
You can add custom CSS to change the appearance of the generated documentation. Create a new CSS file, and include it in your Cargo.toml under the [package.metadata.docs.rs] section:

toml
Copy code
[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "path/to/your/custom.css"]
Now you can add any CSS rules to the custom file to modify the appearance of the Rustdoc output.

Custom JavaScript:
If you need more advanced control over the rendering, you can add custom JavaScript to the generated docs. Create a new JavaScript file and include it in your Cargo.toml as well:

toml
Copy code
[package.metadata.docs.rs]
rustdoc-args = ["--html-in-header", "path/to/your/custom.js"]
With JavaScript, you can reorder sections, hide or show elements, or make other changes to the DOM as needed.

Modify the theme:
Rustdoc has a built-in theme switcher. You can create a custom theme by modifying the theme CSS files located in the src/librustdoc/html/static/themes directory in the Rustdoc source code. You can then include your custom theme in your project, allowing users to switch to it using the theme switcher.

Custom HTML templates:
Rustdoc uses Handlebars templates to generate the HTML output. You can create your own templates to customize the structure of the generated documentation. You'll need to modify the Rustdoc source code, located in the src/librustdoc/html directory, and then build a custom version of Rustdoc to use with your project.

Fork Rustdoc:
If you need extensive customization, you can fork the Rustdoc project, make your desired changes, and use your custom Rustdoc version to generate documentation for your projects. This approach allows you to have full control over the output and functionality but requires more effort to maintain and stay up-to-date with the official Rustdoc releases.

Remember that making significant changes to the appearance or structure of Rustdocs can make it harder for other Rust users to navigate and understand your documentation. Be cautious with customizations and consider the impact on usability before implementing them.
@kianenigma kianenigma added infra issue does not require specific knowledge of the content, and is mainly about the system. generalist Issue requires technical knowledge, but not deeply. labels May 8, 2023
@kianenigma
Copy link
Collaborator Author

both --scrape-exmaples and --scrape-tests unstable features seem interesting; see: rust-lang/cargo#10865

@kianenigma
Copy link
Collaborator Author

What I mean by

Easier distinction between types that are storage and not.

Is something like the deprecated tag here, but for storage.

Screenshot 2023-05-26 at 14 55 09

@sam0x17
Copy link

sam0x17 commented May 26, 2023

We might even be able to do this with some very clever CSS media queries without even needing to inject js, in the event that docs.rs blocks custom js but allows css

@sam0x17
Copy link

sam0x17 commented May 26, 2023

Ok it does indeed work on docs.rs: https://docs.rs/docs_js_injection_test/latest/docs_js_injection_test/

Problem is, I have yet to figure out how to get this same trick to work on local cargo doc, but will see what I can find

@kianenigma
Copy link
Collaborator Author

https://crates.io/crates/doc_item/0.3.0 is pretty amazing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
generalist Issue requires technical knowledge, but not deeply. infra issue does not require specific knowledge of the content, and is mainly about the system.
Projects
None yet
Development

No branches or pull requests

2 participants