metalsmith / layouts

A metalsmith plugin for layouts
MIT License
116 stars 49 forks source link

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

Open webketje opened 9 months ago

webketje commented 9 months ago

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