From 7cb88275fd3c813114271c0a136b12c72c5a172a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 19 Nov 2024 13:25:22 -0400 Subject: content: decompose generateCoverArtwork No visual/site changes yet. This involves introducing an unfortunate mega-hack in generateStickyHeadingContainer, which sets slots on cover artworks. Very scary. Oooooo Otherwise, all cover artwork code is much more compositional. Pass-through slots (`image`) are removed in generateCoverArtwork and a partially-formed `image` slot is accepted instead. --- .../dependencies/generateStickyHeadingContainer.js | 62 ++++++++++++++++++++-- 1 file changed, 57 insertions(+), 5 deletions(-) (limited to 'src/content/dependencies/generateStickyHeadingContainer.js') 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'}, -- cgit 1.3.0-6-gf8a5