From 6ab0063fe64671a47beb8f15d6138c4133b31445 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 13 Jun 2024 12:04:56 -0300 Subject: content: generateQuickDescription: extraReadingLinks slot --- .../dependencies/generateQuickDescription.js | 49 ++++++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/generateQuickDescription.js b/src/content/dependencies/generateQuickDescription.js index f555af28..4c7c944a 100644 --- a/src/content/dependencies/generateQuickDescription.js +++ b/src/content/dependencies/generateQuickDescription.js @@ -34,16 +34,40 @@ export default { hasLongerDescription: query.hasLongerDescription, }), - generate(data, relations, {html, language}) { + slots: { + extraReadingLinks: { + validate: v => v.sparseArrayOf(v.isHTML), + }, + }, + + generate(data, relations, slots, {html, language}) { const prefix = 'misc.quickDescription'; + const actionsWithoutLongerDescription = + (data.hasLongerDescription + ? null + : slots.extraReadingLinks + ? language.$(prefix, 'readMore', { + links: + language.formatDisjunctionList(slots.extraReadingLinks), + }) + : null); + const wrapExpandCollapseLink = (expandCollapse, content) => html.tag('a', {class: `${expandCollapse}-link`}, {href: '#'}, content); const actionsWhenCollapsed = - (data.hasLongerDescription + (data.hasLongerDescription && slots.extraReadingLinks + ? language.$(prefix, 'expandDescription.orReadMore', { + links: + language.formatDisjunctionList(slots.extraReadingLinks), + expand: + wrapExpandCollapseLink('expand', + language.$(prefix, 'expandDescription.orReadMore.expand')), + }) + : data.hasLongerDescription ? language.$(prefix, 'expandDescription', { expand: wrapExpandCollapseLink('expand', @@ -52,7 +76,15 @@ export default { : null); const actionsWhenExpanded = - (data.hasLongerDescription + (data.hasLongerDescription && slots.extraReadingLinks + ? language.$(prefix, 'collapseDescription.orReadMore', { + links: + language.formatDisjunctionList(slots.extraReadingLinks), + collapse: + wrapExpandCollapseLink('collapse', + language.$(prefix, 'collapseDescription.orReadMore.collapse')), + }) + : data.hasLongerDescription ? language.$(prefix, 'collapseDescription', { collapse: wrapExpandCollapseLink('collapse', @@ -81,13 +113,22 @@ export default { data.hasLongerDescription && {class: 'collapsed'}, + !data.hasLongerDescription && + !slots.extraReadingLinks && + {class: 'has-content-only'}, + + !data.hasDescription && + slots.extraReadingLinks && + {class: 'has-external-links-only'}, + [ wrapContent(null, relations.description), wrapContent({class: 'short'}, relations.descriptionShort), wrapContent({class: 'long'}, relations.descriptionLong), + wrapActions(null, actionsWithoutLongerDescription), wrapActions({class: 'when-collapsed'}, actionsWhenCollapsed), wrapActions({class: 'when-expanded'}, actionsWhenExpanded), ])); - } + }, }; -- cgit 1.3.0-6-gf8a5