microbiomedata / NMDC_documentation

Document workflows, schemas, and portal
https://nmdc-documentation.readthedocs.io
2 stars 3 forks source link

Capture source path segment and append to destination path #63

Open eecavanna opened 1 month ago

eecavanna commented 1 month ago

In this branch, I deleted the two original redirects that existed and replaced them with a new one. The new one is designed to capture the portion of the original URL following /reference/metadata and append it to https://w3id.org/nmdc/, and then redirect the user to the resulting URL.

For example: If a user visits https://nmdc-documentation.readthedocs.io/en/latest/reference/metadata/xylene.html, I designed the redirect to redirect them to https://w3id.org/nmdc/xylene (which will, in turn, redirect them to https://microbiomedata.github.io/nmdc-schema/xylene/).

I am not sure this redirection plugin supports having a combination of wildcard and non-wildcard sources, which is what the two original redirects—together—were. It may be the case that the wildcard overrode any other sources. This is not addressed in the plugin's documentation.

eecavanna commented 1 month ago

I have created this PR because I don't know how I can get the "dev" MakeTheDocs site to pull from an arbitrary, non-main branch. Merging this into main will not automatically cause it to be deployed to our production documentation website (or the development documentation website). It will, however, allow me to deploy it to those when I choose to.

I will check with @yxu-lanl about the possibility of deploying this PR branch to the development documentation site.

eecavanna commented 1 month ago

I found a way I could deploy this to https://dev-nmdc-documentation.readthedocs.io for testing, without merging it into main first.

Unfortunately, I misunderstood how the "capturing" of the * worked. Instead of capturing only the part of the source path that the * matches, what gets captured is actually the entire source path.

As a result, instead of https://dev-nmdc-documentation.readthedocs.io/en/dev/reference/metadata/xylene.html redirecting to https://w3id.org/nmdc/Study, it redirects to https://w3id.org/nmdc/reference/metadata/Study (which is not what I want to happen).

eecavanna commented 1 month ago

There's already an issue about this behavior, in the plugin's GitHub repo: https://github.com/documatt/sphinx-reredirects/issues/2

eecavanna commented 1 month ago

I commented on that issue. I'll keep this code in a draft PR for now. I have "unassigned" all the reviewers as I'm not ready for this to be merged in anymore.

eecavanna commented 1 month ago

After having checked the source code of the Sphinx plugin that handles redirects, I am not confident the plugin will be updated to capture the portion of the URL that matches the *.

As an alternative, we could add a RewriteRule in https://github.com/perma-id/w3id.org/blob/master/nmdc/.htaccess to remove the leading /reference/metadata. This isn't something I would do without talking to my team members about it first.