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 an option to redirect trailing slash urls #74

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

LilithHafner
Copy link
Contributor

@LilithHafner LilithHafner commented Mar 10, 2024

Also

  • removes some trailing whitespace (automatically performed by editor, can be reverted if desired)
  • adds test/runtest.jl
  • adds Test as a test dep
  • alphabetizes Project.toml (automatically performed by Pkg, can be reverted if desired)

It's still functionally untested.

Fixes #64

@LilithHafner
Copy link
Contributor Author

The best approach from a website visitor's perspective judged based on web best practices is to serve a 301 redirect. That would be faster, more conventional, and still preserve fragments.

However, for static site hosts that do not support serving custom 301 redirects (e.g. github pages), this is a reasonable alternative. This PR serves a 200 page

shell> curl https://chairmarks.lilithhafner.com/previews/PR80/explanations/#Why-the-name-"Chairmarks.jl"?
<!DOCTYPE html>
<script>
    const u = new URL(window.location.href);
    window.location.replace(u.origin + u.pathname.slice(0,-1) + u.search + u.hash);
</script>
<a href="..explanations">Redirecting to ..explanations</a>
<meta http-equiv="refresh" content="0; URL=../explanations">
<link rel="canonical" href="../explanations">

Which uses javascript to preserve the url fragment. If the javascript fails, then there is both an automatic and manual fallback. Both fallbacks fail to preserve the url fragment.

This PR is tested at LilithHafner/Chairmarks.jl#80

@LilithHafner LilithHafner marked this pull request as ready for review March 10, 2024 18:16
Copy link
Collaborator

@asinghvi17 asinghvi17 left a comment

Choose a reason for hiding this comment

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

Haven't been able to fully review, but this looks promising and it seems it's already working! Will look into this more properly tomorrow.

# reason, the meta http-equiv will proc, dropping fragments
# If that, too fails, there's an ordinary, human readable
# relative link.
#
# This uses a relative canonical link which is bad form, but
# oh well. We don't have access to the full URL until deploy
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may have access to the deploy URL through settings.deploy_url and deploy_decision, so in that situation we could add that in if it's better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A recall trying that and finding that field to be empty.

Project.toml Outdated Show resolved Hide resolved
@asinghvi17
Copy link
Collaborator

Thanks! I will add a couple of small tests, and merge this before the next release!

@LilithHafner
Copy link
Contributor Author

Bump

@asinghvi17 asinghvi17 mentioned this pull request May 9, 2024
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.

Trailing slash gives 404
2 participants