From 8b68f4a816469beda84f3802a0dcecac5a54d16e Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Wed, 16 Oct 2024 13:39:51 +0200 Subject: [PATCH] docs(README): describe extra steps for nested path translation --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 1928f0d3a..8df53618e 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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.