layouts icon indicating copy to clipboard operation
layouts copied to clipboard

Add 'renderContext' (=locals/data) option?

Open webketje opened this issue 7 months ago • 0 comments

To avoid the usecase at https://github.com/metalsmith/collections/issues/79#issuecomment-1027474334 the user could be given the option to transform the render context passed to a template. By default this would be (backwards-compatible):

function renderContext(fileMeta, path, globalMeta) {
  return { ...globalMeta, ...fileMeta }
}

The collections use case can then use a single collections property both on the file & global meta, and the renderContext can be remapped:

function renderContext(fileMeta, path, globalMeta) {
  return { ...globalMeta, ...fileMeta, collections: { all:  globalMeta.collections, own: fileMeta.collections }}
}

Not to mention some manual data imports could be added as well

webketje avatar Nov 20 '23 23:11 webketje