-
Notifications
You must be signed in to change notification settings - Fork 61
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
A helper to add/remove/edit data in a Slice Zone's Slices (mapSliceZone()
)
#303
Comments
mapSliceZone()
)
An initial implementation is being developed in #302. It is being exposed as The following serves as documentation for Things to know
How to use1. Create a mapper
2. Create a mapper record
3. Map Slices in
|
|
Is your feature request related to a problem? Please describe.
By default, Slice Zones only contain data provided directly from the Prismic API. This is sufficient in most cases, but extra data, or less data in some cases, is needed.
Developers can modify their Slice Zone data manually today using
Array.prototype.map()
and custom logic, but the solution is not straightforward. Anyone needing this functionality will need to implement it ad-hoc.Describe the solution you'd like
We could provide a
mapSliceZone()
function that accepts a Slice Zone array and an object of functions that map a particular type of Slice to some other obhject. The function could add, edit, or remove data from a Slice.The following example reshapes Code Block Slices (id:
code_block
) by replacing it with an object containing a singlecodeHTML
property. The property contains HTML produced from ahighlight()
function, which could be a function that calls a syntax highlighting library, like Shiki.Any occurance of a Code Block Slice will be replaced with the mapped version. Note how the function provided to the
code_block
property receives theslice
object. Other data is included, such asslices
, andindex
.A third parameter (
context
) can be provided tounstable_mapSliceZone()
, whose contents will be passed to the function in thecontext
property. The context object is most helpful when mapping functions are defined outside theunstable_mapSliceZone()
calling scope, such as in a different module.Describe alternatives you've considered
Developers can use
Array.prototype.map()
directly and implement custom logic. This helper would do exactly that, but with a framework around how to define that custom logic, along with thorough TypeScript types.Additional context
This feature request has been prototyped internally.
The text was updated successfully, but these errors were encountered: