From 86ad4bafb52a1870e613241cc48591865df540d9 Mon Sep 17 00:00:00 2001 From: rudietuesdays Date: Mon, 4 Oct 2021 14:11:20 -0400 Subject: [PATCH 1/2] fixes issue #17 from upstream; add serializer customization to plugin --- index.js | 6 ++++++ lib/sanity-util.js | 16 +++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 8301356..3ff688d 100644 --- a/index.js +++ b/index.js @@ -95,6 +95,12 @@ module.exports.options = { watch: { default: false, runtimeParameter: 'watch' + }, + serializers: { + marks: { + annotations: [], + }, + types: {}, } }; diff --git a/lib/sanity-util.js b/lib/sanity-util.js index 2094843..d6b3c3c 100644 --- a/lib/sanity-util.js +++ b/lib/sanity-util.js @@ -17,13 +17,19 @@ function convertBlockToHTML({ blocks, cache, entriesById, options, visitedIds }) return blockToHTML.h('img', { src: normalizedImage.url }); }; + const allSerializers = { + types: { + ...options.serializers.types, + image: imageSerializer + }, + marks: { + ...options.serializers.marks + } + } + return blockToHTML({ blocks, - serializers: { - types: { - image: imageSerializer - } - } + serializers: allSerializers, }); } From 7f90a542c2031c210322d62cc3316f4a217a708c Mon Sep 17 00:00:00 2001 From: rudietuesdays Date: Wed, 6 Oct 2021 15:40:00 -0400 Subject: [PATCH 2/2] add defaults to serializer options and logic to check whether they exist --- index.js | 11 +++++++++-- lib/sanity-util.js | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 3ff688d..2a3778e 100644 --- a/index.js +++ b/index.js @@ -97,10 +97,17 @@ module.exports.options = { runtimeParameter: 'watch' }, serializers: { + default: {}, marks: { - annotations: [], + default: { + annotations: { + default: [], + }, + } + }, + types: { + default: {}, }, - types: {}, } }; diff --git a/lib/sanity-util.js b/lib/sanity-util.js index d6b3c3c..b0ebd8e 100644 --- a/lib/sanity-util.js +++ b/lib/sanity-util.js @@ -19,11 +19,11 @@ function convertBlockToHTML({ blocks, cache, entriesById, options, visitedIds }) const allSerializers = { types: { - ...options.serializers.types, + ...(options.serializers && options.serializers.types), image: imageSerializer }, marks: { - ...options.serializers.marks + ...(options.serializers && options.serializers.marks) } }