Skip to content

Commit

Permalink
docs(README): describe extra steps for nested path translation
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Oct 16, 2024
1 parent 3ac213d commit 8b68f4a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- [Pages](#pages)
- [Development](#development)
- [Using `fetchWithToken` for Custom Components in Sanity](#using-fetchwithtoken-for-custom-components-in-sanity)
- [Nested Path Translation](#nested-path-translation)
- [Steganography in Presentation](#steganography-in-presentation)
- [Serving files from `/public`](#serving-files-from-public)
- [OpenGraph image customization](#opengraph-image-customization)
Expand Down Expand Up @@ -188,6 +189,10 @@ export default MyCustomComponent;

By using fetchWithToken, you ensure that all data fetching happens securely, with the server-side API route handling the sensitive token.

### Nested Path Translation

Some extra handling is required for translating paths with multiple slugs/segments, e.g. `/kunder/fram`. In these cases, the `translatePath` function in [`languageMiddleware.tsx`](src/middlewares/languageMiddleware.ts) must be extended to handle the specific path structure. This usually involves checking which document type corresponds to the first path segment (e.g. `kunder` corresponds to the `customerCase` document type), and then finding the document for the second segment (e.g. customer case with slug `fram`).

### Steganography in Presentation

To enable preview functionality in the Presentation view, Sanity applies [steganography](https://www.sanity.io/docs/stega) to the string data. This manipulates the data to include invisible HTML entities to store various metadata. If the strings are used in business logic, that logic will likely break in the Presentation view. To fix this, Sanity provides the `stegaClean` utility to remove this extra metadata. An example of this in action can be found in [CompensationsPreview.tsx](src/compensations/CompensationsPreview.tsx), where JSON parsing of salary data fails without stega cleaning.
Expand Down

0 comments on commit 8b68f4a

Please sign in to comment.