tinloof / sanity-kit

83 stars 11 forks source link

fix: render correct preview titles #88

Closed marcusforsberg closed 1 month ago

marcusforsberg commented 2 months ago

There's an issue with the document preview titles in the navigator. The titles end up always being generated from the pathname, regardless of a document's actual title.

This is problematic, for example, if a page's title and pathname differ:

Screenshot 2024-08-27 at 12 08 55

It's also an issue for non-English titles, for example:

Screenshot 2024-08-27 at 12 09 45

This PR fixes the preview logic so that the correct titles are always shown:

Screenshot 2024-08-27 at 12 11 31

This should make it clear to editors which page is which, even if the pathname differs or if there are special characters or capitalized characters in the title.

I used these components in Sanity's repo as reference for this change:

It seems to work well, but I'm not too well-versed in the inner workings of these parts so there may well be a better way to do it, so I'm open to adjusting this as needed.