From 523243bf1f8ffd7771e1f157655011542c50bc09 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 26 Jul 2023 10:10:03 -0300 Subject: content: transformContent: support index links, preferShortLinkNames --- src/content/dependencies/transformContent.js | 33 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index 7010e9de..6873892b 100644 --- a/src/content/dependencies/transformContent.js +++ b/src/content/dependencies/transformContent.js @@ -27,11 +27,11 @@ const linkValueRelationMap = { }; const linkIndexRelationMap = { - // commentaryIndex: 'linkCommentaryIndex', - // flashIndex: 'linkFlashIndex', - // home: 'linkHome', - // listingIndex: 'linkListingIndex', - // newsIndex: 'linkNewsIndex', + commentaryIndex: 'linkCommentaryIndex', + flashIndex: 'linkFlashIndex', + home: 'linkWikiHome', + listingIndex: 'linkListingIndex', + newsIndex: 'linkNewsIndex', }; function getPlaceholder(node, content) { @@ -79,13 +79,15 @@ export default { determineData: { // No value at all: this is an index link. - if (!replacerValue) { + if (!replacerValue || replacerValue === '-') { + data.toIndex = true; break determineData; } // Nothing to find: the link operates on a path or string, not a data object. if (!spec.find) { data.value = replacerValue; + data.toIndex = false; break determineData; } @@ -103,6 +105,7 @@ export default { // Something was found: the link operates on that thing. data.thing = thing; + data.toIndex = false; } const {transformName} = spec; @@ -159,6 +162,7 @@ export default { link: relation(name, arg), label: node.data.label, hash: node.data.hash, + toIndex: node.data.toIndex, } : getPlaceholder(node, content)); @@ -171,7 +175,7 @@ export default { if (thing) { return relationOrPlaceholder(node, linkThingRelationMap[key], thing); - } else if (value) { + } else if (value && value !== '-') { return relationOrPlaceholder(node, linkValueRelationMap[key], value); } else { return relationOrPlaceholder(node, linkIndexRelationMap[key]); @@ -185,6 +189,11 @@ export default { validate: v => v.is('inline', 'multiline', 'lyrics'), default: 'multiline', }, + + preferShortLinkNames: { + type: 'boolean', + default: false, + }, }, generate(data, relations, slots, {html, language}) { @@ -205,11 +214,17 @@ export default { return {type: 'text', data: linkNode.data}; } - const {link, label, hash} = linkNode; + const {link, label, hash, toIndex} = linkNode; return { type: 'link', - data: link.slots({content: label, hash}), + data: + (toIndex + ? link.slots({content: label, hash}) + : link.slots({ + content: label, hash, + preferShortName: slots.preferShortLinkNames, + })), }; } -- cgit 1.3.0-6-gf8a5