diff options
Diffstat (limited to 'src/content/dependencies/generateStickyHeadingContainer.js')
-rw-r--r-- | src/content/dependencies/generateStickyHeadingContainer.js | 62 |
1 files changed, 57 insertions, 5 deletions
diff --git a/src/content/dependencies/generateStickyHeadingContainer.js b/src/content/dependencies/generateStickyHeadingContainer.js index 7f271715..ab607a4f 100644 --- a/src/content/dependencies/generateStickyHeadingContainer.js +++ b/src/content/dependencies/generateStickyHeadingContainer.js @@ -28,11 +28,63 @@ export default { html.tag('div', {class: 'content-sticky-heading-cover'}, {[html.onlyIfContent]: true}, - // TODO: We shouldn't need to do an isBlank check here, - // but a live blank value doesn't have a slot functions, so. - (html.isBlank(slots.cover) - ? html.blank() - : slots.cover.slot('mode', 'thumbnail')))), + (() => { + if (html.isBlank(slots.cover)) { + return html.blank(); + } + + // Try very hard to set the cover's 'mode' slot to 'thumbnail' + // and its 'details' slot to html.blank(). + let setMode = false; + let setDetails = false; + let cover = slots.cover; + while (true) { + if (!cover) { + return html.blank(); + } + + if (!(cover instanceof html.Template)) { + return cover; + } + + // The cover from `slots` is already cloned (since it's + // mutable), but later ones are not, and for extremely scary + // content function infrastructure reasons, it is possible + // for the identity of the content of the clone-template + // to be the same as the cloned template. + if (cover !== slots.cover) { + cover = cover.clone(); + } + + if (!setMode) { + try { + cover.setSlot('mode', 'thumbnail'); + setMode = true; + } catch { + // No mode slot, or it doesn't allow 'thumbnail'. + } + } + + if (!setDetails) { + try { + cover.setSlot('details', html.blank()); + setDetails = true; + } catch { + // No details slot, or it doesn't allow html.blank(). + // We're setting a blank instead of null because null is + // always allowed, and can carry a different semantic + // meaning, like "put something else here by default + // instead please". + } + } + + if (setMode && setDetails) { + return cover; + } + + cover = cover.content; + } + })())), ]), html.tag('div', {class: 'content-sticky-subheading-row'}, |