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

v3 - manual Sanity-controlled redirects #562

Merged
merged 12 commits into from
Sep 10, 2024

Conversation

mathiazom
Copy link
Contributor

@mathiazom mathiazom commented Sep 2, 2024

Further explanation is found here: #561

Added support for defining temporary redirects from Sanity Studio. Redirect destination can be either a reference to a page defined in Sanity, or an external URL. Support for a static internal slug has not been added, but might be introduced in the future.

Redirects are performed in a Next.js middleware. Using a middleware ensures that all redirects are up-to-date, but will likely reduce performance. The alternative is a redirects list generated at build-time. This will likely improve performance, but has the disadvantage of outdated redirects between builds. This could be adressed by adding some type of hook that would trigger a rebuild when new slugs are published.


Visual Overview (Image/Video)

Page reference:

image

External URL:

image

Checklist

Please ensure that you’ve completed the following checkpoints before submitting your pull request:

  • Documentation: Relevant documentation has been added or updated (if applicable).
  • Testing: Have you tested your changes thoroughly?

Copy link

vercel bot commented Sep 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
variant-no ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 10, 2024 1:36pm
variant-se-2 ✅ Ready (Inspect) Visit Preview Sep 10, 2024 1:36pm

@mathiazom
Copy link
Contributor Author

TODO: add documentation

@mathiazom mathiazom force-pushed the feat/v3-manual-redirects-from-sanity branch from b140f11 to e125198 Compare September 2, 2024 13:46
@mathiazom
Copy link
Contributor Author

Should we even allow adding permanent redirects? These can not be undone realiably since they are stored on the client.

@anemne
Copy link
Contributor

anemne commented Sep 3, 2024

Nice! Det som kanskje kunne vært nyttig hadde vært å referere til de sidene vi har? Så i stedet for å skrive inn manuelt så kan man velge page (slik som man gjør i navigation manager).

I tillegg bør man kanskje vurdere om man skal kunne legge til flere redirects på samme redirect?

@mathiazom
Copy link
Contributor Author

Nice! Det som kanskje kunne vært nyttig hadde vært å referere til de sidene vi har? Så i stedet for å skrive inn manuelt så kan man velge page (slik som man gjør i navigation manager).

Veldig godt poeng 👍 Er det fortsatt interessant å kunne skrive inn manuelt, eller kun Sanity pages?

@mathiazom
Copy link
Contributor Author

I tillegg bør man kanskje vurdere om man skal kunne legge til flere redirects på samme redirect?

Mener du at flere source paths kan peke til samme destination path? F.eks. /katt, /hund, /hest/dyr

Det er absolutt en mulighet 👍

@anemne
Copy link
Contributor

anemne commented Sep 3, 2024

Nice! Det som kanskje kunne vært nyttig hadde vært å referere til de sidene vi har? Så i stedet for å skrive inn manuelt så kan man velge page (slik som man gjør i navigation manager).

Veldig godt poeng 👍 Er det fortsatt interessant å kunne skrive inn manuelt, eller kun Sanity pages?

Hmm, er det mulig å la brukeren skrive inn, men at det gir feil hvis det ikke finnes en page? Og filtrere bort de som ikke er aktuelle i dropdown-menyen. Da unngår man brukerfeilen ved å redirecte til en page som ikke finnes.

@anemne
Copy link
Contributor

anemne commented Sep 3, 2024

I tillegg bør man kanskje vurdere om man skal kunne legge til flere redirects på samme redirect?

Mener du at flere source paths kan peke til samme destination path? F.eks. /katt, /hund, /hest/dyr

Det er absolutt en mulighet 👍

Ja stemmer!

@mathiazom
Copy link
Contributor Author

Hmm, er det mulig å la brukeren skrive inn, men at det gir feil hvis det ikke finnes en page? Og filtrere bort de som ikke er aktuelle i dropdown-menyen. Da unngår man brukerfeilen ved å redirecte til en page som ikke finnes.

Laget et forslag til løsning nå, se bilder over. Her velger du om du ønsker å bruke en referanse til en intern side, eller en statisk slug. Feltet under typen vil da vise felt for slug eller intern side avhengig av typevalget.

src/middleware.ts Outdated Show resolved Hide resolved
src/middleware.ts Outdated Show resolved Hide resolved
studio/components/RedirectThumbnail.tsx Outdated Show resolved Hide resolved
studio/schemas/schemaTypes/slug.ts Show resolved Hide resolved
@mathiazom mathiazom marked this pull request as ready for review September 10, 2024 06:35
@mathiazom
Copy link
Contributor Author

Should we even allow adding permanent redirects? These can not be undone realiably since they are stored on the client.

Decided to omit support for permanent redirects for now. This can be introduced later if needed.

@mathiazom mathiazom requested a review from anemne September 10, 2024 13:38
Copy link
Contributor

@anemne anemne left a comment

Choose a reason for hiding this comment

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

👌

@mathiazom mathiazom merged commit ce18813 into v3 Sep 10, 2024
6 checks passed
@mathiazom mathiazom deleted the feat/v3-manual-redirects-from-sanity branch September 10, 2024 13:39
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.

3 participants