Skip to content

Conversation

@sin
Copy link
Contributor

@sin sin commented Dec 26, 2021

The links in the “See Also” section on topic pages lead to a 404. This is very annoying since RDocumentation is often the first result for searches related to R packages. The missing page is:

/link/:topic?package=:package&version=:version

And it should point to:

/packages/:package/versions/:version/topics/:topic

However, It can’t be simply fixed by redirecting to the correct URL because the function names in the “See Also” section don’t always map directly to topic pages. There is an API endpoint with the same path that resolves the correct topic page and fallbacks with a search results:

[API_URL]/link/:topic?package=:package&version=:version

The problem is, it redirects to a page in the API domain, instead of returning JSON with a correct relative URL.

[API_URL]/packages/:package/versions/:version/topics/:topic

The solution: create the link page and fetch the corresponding API endpoint, get the URL it redirects to from response.url, strip the domain name and redirect.

This can be improved further by adding an API endpoint that returns the correct URL or by resolving the URL when the link is created thus saving on two redirects.

This solves #65 and #74.

…p#74)

The links in the “See Also” section on topic pages lead to a 404. This is very annoying since RDocumentation is often the first result for searches related to R packages. The missing page is:

`/link/:topic?package=:package&version=:version`

It can’t be fixed by simply redirecting to
`/packages/:package/versions/:version/topics/:topic` because the function names in the “See Also” section don’t always map directly to topic pages.

There is an API endpoint with the same path that resolves the correct topic page and fallbacks with a search results.

`[API_URL]/link/:topic?package=:package&version=:version`

https://github.com/datacamp/RDocumentation-app/blob/aa71a42af087a850df69d5c7ecbc01316cc31f0e/api/controllers/TopicController.js#L263-L367

The problem is, it redirects to a page in the API domain, instead of returning JSON with a correct relative URL.

`[API_URL]/packages/:package/versions/:version/topics/:topic`

The solution: create the link page and fetch the corresponding API endpoint, get the URL it redirects to from response.url, strip the domain name and redirect.

This can be improved further by adding an API endpoint that returns the correct URL or by resolving the URL when the link is created.
@sin sin changed the title fix: fix broken links in the “See Also” section (#65, #74) fix: fix broken links in the “See Also” section Dec 26, 2021
@TxMat
Copy link

TxMat commented Jan 3, 2022

thank you for this fix hope it'll be merged soon

@sin
Copy link
Contributor Author

sin commented Jan 24, 2022

Hi, @ncarchedi, @ddmkr can I expect this to be merged? It's a non breaking change that greatly improves the user experience.

@sin sin mentioned this pull request Mar 31, 2022
@ariliso
Copy link

ariliso commented Apr 5, 2022

@ztsorojev ? I saw you merged something recently, is there a reason not to do this? Usability is seriously impaired.

@ztsorojev
Copy link
Contributor

@sin Thank you for your contribution!! 🙏 Sorry that I replied so late! And thanks @ariliso for tagging me!
I tested your code, it's working so I will merge it now! It doesn't solve all the links from #74 unfortunately, but it's already a great improvement. I will look more into why other links are broken.

@ztsorojev ztsorojev merged commit bfe4557 into datacamp:main Apr 11, 2022
@ztsorojev ztsorojev mentioned this pull request Apr 11, 2022
@sin sin changed the title fix: fix broken links in the “See Also” section fix broken links in the “See Also” section Apr 21, 2022
@sin
Copy link
Contributor Author

sin commented Apr 21, 2022

@ztsorojev Thank you! It also fixed the links in the body of text, not only the “See Also” section.

I've found out that we can sanitize the input to make it work more often.

For example, this link doesn't work: /link/all.equal()?package=dplyr
But this works: /link/all.equal?package=dplyr

Dropping the brackets from the function name would fix a lot of links. I'll create another PR shortly.

sin added a commit to sin/rdocumentation-2.0 that referenced this pull request Apr 22, 2022
Some of the links are formatted as `function_name()` or `library::function_name()` instead of just `function_name`. This is the convention in the tidyverse packages' docs.

This change simply removes the brackets and splits the library and function names.

Link to `tidyselect::vars_pull()` from tidyr:

Before: /link/tidyselect::vars_pull()?package=tidyr
After:  /link/vars_pull?package=tidyselect
ztsorojev added a commit that referenced this pull request Apr 22, 2022
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.

4 participants