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

Add a basic version selector to rendered documentation #846

Merged
merged 3 commits into from
Nov 20, 2020
Merged

Add a basic version selector to rendered documentation #846

merged 3 commits into from
Nov 20, 2020

Conversation

michallepicki
Copy link
Contributor

Adds dropdown to switch to a different package version. Closes #844

@michallepicki
Copy link
Contributor Author

This is how it looks right now:
image

With the docs_config.js path it will work out of the box on hexdocs. The path should probably be configurable.

@michaeljones
Copy link
Contributor

Very cool to see! :)

Copy link
Member

@lpil lpil 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! I left a comment inline.

@@ -5,11 +5,13 @@
<meta name="viewport" content="width=device-width" />
<title>{{ page_title }}</title>
<link rel="stylesheet" href="{{ unnest }}/index.css" type="text/css" />
<script src="{{ unnest }}/docs_config.js"></script>
Copy link
Member

Choose a reason for hiding this comment

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

Does this file get automatically added by hexdocs? If so can we add a comment here to explain that.

@michallepicki
Copy link
Contributor Author

@lpil What do you think about the project version in the toml version file? Should it be required? There is a duplication with the .app file, and I don't know what rebar3_hex uses - I think it would be good for the library maintainer to configure current version in one spot

@michallepicki michallepicki changed the title Add a basic versions dropdown to the top bar Add a basic versions dropdown to rendered documentation top bar Nov 15, 2020
@michallepicki
Copy link
Contributor Author

Alternatively, I can not use the current package version at all, have an empty span in place and only fill it in with a dropdown if the versionNodes from docs_config.js is loaded. To detect the current version to make it selected and visible, current page URL could be used (find the version which URL is the beginning of current page's URL).

@lpil
Copy link
Member

lpil commented Nov 15, 2020

In Michael's pull request I was suggesting that it was made mandatory and a check is added to ensure that the version in gleam.toml matches the one in .app. We don't have a parser for that file though so it would probably have to be something simple like checking for a substring to start.

What do you think?

@michallepicki
Copy link
Contributor Author

I like the idea! I will try to get something working, I don't know much Rust but I always wanted to learn more about it

@michallepicki
Copy link
Contributor Author

If @michaeljones gets around to it sooner then that's fine as well and I can update this PR accordingly.

@michaeljones
Copy link
Contributor

michaeljones commented Nov 15, 2020 via email

@michallepicki
Copy link
Contributor Author

One more thing I'll note here so that I won't forget: ExDoc currently also tries to redirect to the same page. They do that by splitting the current URL by slashes, taking just the last (file) part and appending it to chosen version URL. Then they do an AJAX call first, and if it succeeds, they navigate to that page. If it fails, they navigate to just the version URL. code

I did not include this here because Elixir has a flat documentation file structure and Gleam has files nested in subdirectories. Also I think it's kind of a hack. But it works so maybe if I don't come up with anything better, I will include something similar here.

@lpil
Copy link
Member

lpil commented Nov 18, 2020

Thanks for the info @michallepicki . I agree it's not clear exactly what the best approach for that is yet. Let's hold off for now and tackle that later.

</head>
<body>
<header class="page-header">
<h2>
{{ project_name }}<!-- - {{ project_version }} -->
{{ project_name }}
<span id="project-version"> - v{{ project_version }} </span>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about that, do we want to show the version now whenever the docs_config.js wasn't loaded?

Copy link
Member

Choose a reason for hiding this comment

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

I think this is good. We can always improve it later :)

@michallepicki michallepicki marked this pull request as ready for review November 20, 2020 16:07
@michallepicki
Copy link
Contributor Author

Updated, should be ready for review now! To test this, after generating docs, I was downloading the docs_config.js file from HexDocs and saving it in the generated docs directory. Clicking a link for a chosen version in the dropdown should open this version's docs on HexDocs.

@michallepicki
Copy link
Contributor Author

I think I was too quick, looks bad on chrome:
image

I'll find some time this week to test on various browsers. But the versions switcher should be functional now (even if ugly on some browsers).

@michallepicki
Copy link
Contributor Author

The appearance on Chrome should now be better. I used an svg background to style the dropdown because with the ::after pseudo-element, I could not find a good absolute positioning that worked on both Chrome and Firefox.

@michallepicki michallepicki changed the title Add a basic versions dropdown to rendered documentation top bar Add a basic version selector to rendered documentation Nov 20, 2020
@michallepicki
Copy link
Contributor Author

Published something temporarily to https://michallepicki.github.io/otp/ for testing

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Very nice! This'll be a big usability improvement going forward. Thanks!

@lpil lpil merged commit a729ec2 into gleam-lang:main Nov 20, 2020
@michallepicki
Copy link
Contributor Author

Unfortunately even after removing the svg rotation I still see a double arrow on Android:
image

I'll try to find a fix and submit a followup PR

@michallepicki michallepicki deleted the 844-add-versions-dropdown branch November 20, 2020 21:22
@lpil
Copy link
Member

lpil commented Nov 20, 2020

Good find. Thank you

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.

Add a versions dropdown to package documentation
3 participants