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

Automatically update _redirects file #522

Open
zmitchell opened this issue Apr 14, 2023 · 12 comments
Open

Automatically update _redirects file #522

zmitchell opened this issue Apr 14, 2023 · 12 comments
Assignees
Labels
site Improvements to the site infrastructure or content presentation

Comments

@zmitchell
Copy link
Contributor

Manually keeping track of redirects is bound to fail when someone forgets. We should use automatic tooling to help us with this. There are tools like sphinxcontrib.redirects to help with this.

It doesn't sound like this package adds an HTTP status code at the end, but the fact that a changed _redirects file shows up in git status is enough to remind you that you may want to add one if the default 302 isn't sufficient.

@zmitchell zmitchell added the site Improvements to the site infrastructure or content presentation label Apr 14, 2023
@zmitchell
Copy link
Contributor Author

So I misread what this Sphinx module does, it tracks which files have redirect to one another, but not which URLs redirect to one another.

These are the Sphinx-specific redirect modules I found:

  • sphinx-reredirects, docs
    • Detects a change from foo.md to foo2.md, generating both foo.html and foo2.html with a <meta http-refresh="..."> tag in foo.html to redirect to foo2.html.
    • Pros
      • Is host-agnostic i.e. doesn't rely on Cloudflare Pages specific _redirects file
    • Cons
      • Could lead to significant bloat over time with many empty pages simply existing to serve redirects
  • sphincontrib.redirects
    • Very simple, puts file redirects into a configurable file path
    • Records foo.md -> foo2.md, including the file extensions
    • Last update was 10 months ago
    • Pros
      • Works similar to what we already have
    • Cons
      • Only works with the Sphinx singlehtml builder, which we can build with (it's in the Makefile), but is unsuitable for the whole site
      • We would have to do post-processing on the redirects file to format it how Cloudflare Pages wants
        • Wouldn't be terribly complicated e.g. sed -i 's/.md//g _redirects
  • sphinx-rediraffe
    • A mix of the above two, generates the redirecting pages and can automatically manage a redirects file
    • Lots of features, probably more than we want or need
    • Does a graph traversal of redirects to make sure that chained redirects are resolved to a single redirect
    • Pros
      • Lots of features and configuration options
      • Is host-agnostic
    • Cons
      • Lots of features and configuration options
      • Could lead to significant bloat over time with many empty pages simply existing to serve redirects
      • We would have to do post-processing on the redirects file to format it how Cloudflare Pages wants
        • Wouldn't be terribly complicated e.g. sed -i 's/.md//g _redirects

Considering the options I think sphinx-rediraffe is probably the way to go given how configurable it is. Unfortunately none of these three modules are in nixpkgs. I would be willing to add them to nixpkgs if someone wants to guide me through that process. Maintenance would be minimal as none of these packages see frequent updates.

@fricklerhandwerk
Copy link
Collaborator

Thanks for doing the research!

We could do a mob session for adding a package, and try to follow official documentation in order to see how well it works.

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-04-24-documentation-team-meeting-notes-43/27558/1

@infinisil
Copy link
Member

Brief note from the meeting:

--override-input nixpkgs path:$HOME/src/nixpkgs should work

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-05-08-documentation-team-meeting-notes-46/27965/1

@henrik-ch
Copy link
Contributor

Some work that has been done on this can be found under:
https://github.com/zmitchell/nixpkgs
branch: sphinxext-rediraffe

Look for the notes here to get an idea how the default.nix was created and how to run it:
https://discourse.nixos.org/t/2023-04-24-documentation-team-meeting-notes-43/27558

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-06-01-documentation-team-meeting-notes-51/28635/1

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-07-27-documentation-team-meeting-notes-67/30998/1

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-07-27-learning-journey-working-group-meeting-notes-19/31151/1

@yukiisbored yukiisbored self-assigned this Aug 1, 2023
@zmitchell
Copy link
Contributor Author

zmitchell commented Sep 25, 2023

Me, @yukiisbored, and @henrik-ch worked on this together and we have automatic redirects working with a couple of caveats:

  • We need this repo converted to use nixpkgs instead of poetry. I have an in-progress branch that does this.
  • We need sphinx-sitemap to also be packaged for nixpkgs.
  • Configure sphinxext-rediraffe:
    • Create a source/redirects.txt file and set rediraffe_redirects = "redirects.txt" in conf.py.
    • Set rediraffe_branch to some git ref, most likely origin/master.
  • You can still use the development server, but you must call nix develop --command python live.py instead of ./live.
  • Add rediraffecheckdiff and rediraffewritediff to CI (former just checks for redirects, latter writes to a redirects.txt file, which we also need to create).

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-10-05-documentation-team-meeting-notes-84/33877/1

@asymmetric
Copy link
Contributor

See related PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
site Improvements to the site infrastructure or content presentation
Projects
Status: No status
Development

No branches or pull requests

7 participants