forked from rust-lang/rfcs
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Create RFC for bundling local images in rustdoc output #3
Closed
Closed
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6ac27fa
Create RFC for bundling local images in rustdoc output
GuillaumeGomez b6e3a99
Clarifications and add more examples
GuillaumeGomez 864c222
Improve hash computation explanations and add new "Possible extension…
GuillaumeGomez 40b54df
Rename local.resources folder into doc.files
GuillaumeGomez f9440f1
Remove crate name from the local resources folder path
GuillaumeGomez 4bfda8c
Add information about what happen in case a file isn't found
GuillaumeGomez 088cc0c
Explain better why both absolute and relative paths are necessary
GuillaumeGomez 0d02c9f
Mention published packages
GuillaumeGomez b0383eb
Improve explanations for absolute paths in docs.rs
GuillaumeGomez 021c95f
* Rewrite motivation section.
GuillaumeGomez 1f287b2
* Mention that `html_favicon_url` and `html_logo_url` will also rely …
GuillaumeGomez b1203a5
Fix docs.rs appearance and add explanation for cross-crate inlined im…
GuillaumeGomez c74baba
Add missing backtick around "docs.rs"
GuillaumeGomez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
Rustdoc: Bundle local images | ||
|
||
- Feature Name: NONE | ||
- Start Date: 2023-02-06 | ||
- RFC PR: [rust-lang/rfcs#0000](https://github.com/rust-lang/rfcs/pull/0000) | ||
- Rust Issue: [rust-lang/rust#32104](https://github.com/rust-lang/rust/issues/32104) | ||
|
||
# Summary | ||
[summary]: #summary | ||
|
||
This RFC proposes to allow the bundling of local images in rustdoc HTML output. A draft implementation is available as [#107640](https://github.com/rust-lang/rust/pull/107640). | ||
|
||
# Motivation | ||
[motivation]: #motivation | ||
|
||
Currently, rustdoc does not allow for the inclusion of local images in the generated output. This limits users from customizing their rustdoc output by adding images to their documentation as they currently need to host them on a web server so they can be available from anywhere, but therefore requiring an access to the internet. Bundling local images would enable users to customize their rustdoc output and make it more visually appealing. | ||
|
||
This would make the documentation more engaging and easier to understand while lowering the amount of effort required to achieve a better result. | ||
|
||
# Guide-level explanation | ||
[guide-level-explanation]: #guide-level-explanation | ||
|
||
This RFC proposes to allow rustdoc to include local images in the generated documentation by copying them into the output directory. | ||
|
||
This would be done by allowing users to specify the path of a local resource file in doc comments. The resource file would be stored in the `doc.files` folder. The `doc.files` folder will be at the "top level" of the rustdoc output level (at the same level as the `static.files` or the `src` folders). | ||
|
||
The only local resources considered will be the ones in the markdown image syntax: `![resource title](path)`, where `<path>` is the path of the resource file relative to the source file. | ||
|
||
The path could be either a relative path (`../images/my_image.png`) or an absolute path (like `/home/user/project/images/my_image.png` or `C:/Users/user/project/images/my_image.png`) so that paths can be constructed using `OUT_DIR`: | ||
|
||
```rust | ||
/// Using a local image | ||
#[doc=concat!("![with absolute path](", env!("OUT_DIR"), "/local/image.png)")] | ||
/// | ||
/// Using a local image ![with relative path](../local/image.png) | ||
GuillaumeGomez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
If the path isn't referring to a file, a warning will be emitted and rustdoc will left the path unchanged in the generated documentation. | ||
|
||
Important to be noted for published crates: local resources need to be bundled with the crate so they can be retrieved by rustdoc and absolute paths won't work. | ||
GuillaumeGomez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The local resources files are not affected by the `--resource-suffix`. | ||
|
||
The impact on `docs.rs` would also be very minimal as the size of a published crate resources is limited to a few megabytes. The only thing needed would be to handle the new `doc.files` folder. | ||
|
||
# Reference-level explanation | ||
[reference-level-explanation]: #reference-level-explanation | ||
|
||
A new rustdoc pass will be added which would go through all documentation to gather local resources into a map. | ||
|
||
Then in HTML documentation generation, the local resources pathes will be replaced by their equivalent linking to the output directory instead. | ||
|
||
The local resources files will be renamed as follows: `{original filename}-{hash}{extension}`. The `{hash}` information will be computed from the local resource file content. | ||
|
||
You can look at what the implementation could look like in [#107640](https://github.com/rust-lang/rust/pull/107640). | ||
|
||
# Drawbacks | ||
[drawbacks]: #drawbacks | ||
|
||
Allowing local resources in rustdoc output could lead to big output files if users include big resource files. This could lead to slower build times and increase the size of generated documentation (in particular in case of very big local resources!). | ||
GuillaumeGomez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Prior art | ||
[prior-art]: #prior-art | ||
|
||
- [sphinx](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-latex_additional_files) | ||
- [haddock](https://haskell-haddock.readthedocs.io/en/latest/invoking.html?highlight=image#cmdoption-theme): it's mentioned in this command documentation that local files in the given directory will be copied into the generated output directory. | ||
- [doxygen](https://doxygen.nl/manual/commands.html#cmdimage): supported through `\image`. | ||
|
||
Another approach to this feature: | ||
|
||
[ePUB packages](https://www.w3.org/publishing/epub3/epub-packages.html#sec-pkg-manifest) use explicitly-declared manifests. It allows to have a fallback chain mechanism (going through resources for an entry until an available resource is found). | ||
|
||
# Rationale and alternatives | ||
[rationale-and-alternatives]: #rationale-and-alternatives | ||
|
||
Currently, to provide resources, users need to specify external URLs for resources or inline them (if possible like the `svg` image format) directly into the documentation. It has the advantage to avoid the problem of large output files, but it also requires users to upload their resources to a web server to make them available everywhere. | ||
GuillaumeGomez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
GuillaumeGomez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Unresolved Questions | ||
[unresolved-questions]: #unresolved-questions | ||
|
||
- Should we put a size limit on the local resources? | ||
- Should we somehow keep the original local resource filename instead of just using a number instead? | ||
GuillaumeGomez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- Should we use this feature for the logo if it's a local file? | ||
|
||
# Possible extensions | ||
[possible-extensions]: #possible-extensions | ||
|
||
This feature could be extended to DOM content using local resources. It would require to add parsing for HTML tags attributes. For example: | ||
|
||
```html | ||
/// <video src="../some-video.mp4"> | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the confusion in Zulip, this probably needs to be a bit more explicit about the motivation here: