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

docs: link examples & tutorial of right version on docs.rs #497

Merged
merged 1 commit into from
Aug 8, 2023

Conversation

not-my-profile
Copy link
Contributor

Previously the start page of the documentation on docs.rs for chumsky linked the examples and tutorial from the main branch, no matter which version you selected on docs.rs.

So e.g. https://docs.rs/chumsky/0.9.2/chumsky/ links https://github.com/zesterer/chumsky/blob/main/examples/brainfuck.rs which is confusing since the main branch currently contains the source code for the upcoming 1.0.0, which has a different API.

This commit remedies this for future releases by separating the link labels and URLs using CommonMark link reference definitions1 and overriding them in src/lib.rs, building the correct URLs via CARGO_PKG_VERSION2.

This trick will require git tags to be created for all future versions (so e.g. if 0.9.3 will be released the commit will have to be tagged with "0.9.3").

@not-my-profile
Copy link
Contributor Author

I just realized that tutorial.md has several links to docs.rs so it would probably best to move it into a module within the crate so that the links point to the right version. An example of a project that does this is Polars (see polars::docs). However I'd rather leave this to a followup PR (if you see the merit).

@not-my-profile
Copy link
Contributor Author

not-my-profile commented Aug 2, 2023

(And it would probably make sense to backport this to the legacy branch.)

@zesterer
Copy link
Owner

zesterer commented Aug 2, 2023

Thanks! Do you have any external information I could read about this technique?

Feel free to ignore tutorial.md for now, it's due to be replaced as part of the new guide anyway :)

@not-my-profile
Copy link
Contributor Author

not-my-profile commented Aug 2, 2023

The technique relies on former link definitions taking precedence over latter link definitions which is specified by CommonMark, see example 204. Rustdoc uses the pulldown_cmark Markdown parser which is CommonMark compliant so this works.

[tutorial.md is] due to be replaced as part of the new guide anyway :)

Ah right ... I see that the new guide does exactly what I suggested (being part of the crate) ... so that's great :)

(updated the commit message to link this CommonMark example)

@not-my-profile not-my-profile marked this pull request as draft August 2, 2023 15:46
@not-my-profile not-my-profile marked this pull request as ready for review August 2, 2023 15:48
Copy link
Owner

@zesterer zesterer left a comment

Choose a reason for hiding this comment

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

Thanks! Looks like there's a small conflict to resolve before merge though.

Previously the start page of the documentation on docs.rs for chumsky
linked the examples and tutorial from the main branch, no matter
which version you selected on docs.rs.

So e.g. https://docs.rs/chumsky/0.9.2/chumsky/ links
https://github.com/zesterer/chumsky/blob/main/examples/brainfuck.rs
which is confusing since the main branch currently contains the source
code for the upcoming 1.0.0, which has a different API.

This commit remedies this for future releases by separating the link labels
and URLs using CommonMark link reference definitions and overriding[1]
them in src/lib.rs, building the correct URLs via CARGO_PKG_VERSION[2].

This trick will require git tags to be created for all future versions
(so e.g. if 0.9.3 will be released the commit will have to be tagged
with "0.9.3").

[1]: https://spec.commonmark.org/0.30/#example-204
[2]: https://doc.rust-lang.org/cargo/reference/environment-variables.html
@zesterer
Copy link
Owner

zesterer commented Aug 8, 2023

Thanks!

@zesterer zesterer merged commit 53bc553 into zesterer:main Aug 8, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants