From 063d985d6ac4da4547e335a9c8740a1ec9f21570 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 20:53:56 -0300 Subject: content: linkTemplate: display message when content missing --- src/content/dependencies/linkTemplate.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/linkTemplate.js b/src/content/dependencies/linkTemplate.js index dab81ad3..2a9261e2 100644 --- a/src/content/dependencies/linkTemplate.js +++ b/src/content/dependencies/linkTemplate.js @@ -5,6 +5,7 @@ export default { 'appendIndexHTML', 'getColors', 'html', + 'language', 'to', ], @@ -23,6 +24,7 @@ export default { appendIndexHTML, getColors, html, + language, to, }) { let href = slots.href; @@ -64,6 +66,8 @@ export default { style, title, }, - slots.content); + (html.isBlank(slots.content) + ? language.$('misc.missingLinkContent') + : slots.content)); }, } -- cgit 1.3.0-6-gf8a5 From 08da14a19bd52b759d7844fa45fed12df79ddf75 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 20:54:52 -0300 Subject: content: linkThing: handle name-undefined things gracefully --- src/content/dependencies/linkThing.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/linkThing.js b/src/content/dependencies/linkThing.js index 4ebf4d76..e3e2608f 100644 --- a/src/content/dependencies/linkThing.js +++ b/src/content/dependencies/linkThing.js @@ -44,16 +44,15 @@ export default { generate(data, relations, slots, {html}) { const path = [data.pathKey, data.directory]; - let content = slots.content; - const name = (slots.preferShortName - ? data.nameShort ?? data.name - : data.name); + ? data.nameShort ?? data.name ?? null + : data.name ?? null); - if (html.isBlank(content)) { - content = name; - } + const content = + (html.isBlank(slots.content) + ? name + : slots.content); let color = null; if (slots.color === true) { -- cgit 1.3.0-6-gf8a5 From 6645e6e8e0e58c59d1660767181bb32efbf7930a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 20:55:21 -0300 Subject: content: transformContent: don't override previously set link slots --- src/content/dependencies/transformContent.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index eed00882..9a135eef 100644 --- a/src/content/dependencies/transformContent.js +++ b/src/content/dependencies/transformContent.js @@ -370,16 +370,18 @@ export default { const {link, label, hash, toIndex} = linkNode; - return { - type: 'link', - data: - (toIndex - ? link.slots({content: label, hash}) - : link.slots({ - content: label, hash, - preferShortName: slots.preferShortLinkNames, - })), - }; + // These are removed from the typical combined slots({})-style + // because we don't want to override slots that were already set + // by something that's wrapping the linkTemplate or linkThing + // template. + if (label) link.setSlot('content', label); + if (hash) link.setSlot('hash', hash); + + if (toIndex) { + link.setSlot('preferShortName', slots.preferShortLinkNames); + } + + return {type: 'link', data: link}; } case 'tag': { -- cgit 1.3.0-6-gf8a5 From 42a81b7172c856ad611431ef7d7b468d5b1ffbfd Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 21:01:15 -0300 Subject: content: transformContent: support [[site/media/root:path]] --- src/content/dependencies/linkPathFromMedia.js | 13 +++++++++++++ src/content/dependencies/linkPathFromRoot.js | 13 +++++++++++++ src/content/dependencies/linkPathFromSite.js | 13 +++++++++++++ src/content/dependencies/transformContent.js | 6 +++--- 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/content/dependencies/linkPathFromMedia.js create mode 100644 src/content/dependencies/linkPathFromRoot.js create mode 100644 src/content/dependencies/linkPathFromSite.js (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/linkPathFromMedia.js b/src/content/dependencies/linkPathFromMedia.js new file mode 100644 index 00000000..34a2b857 --- /dev/null +++ b/src/content/dependencies/linkPathFromMedia.js @@ -0,0 +1,13 @@ +export default { + contentDependencies: ['linkTemplate'], + + relations: (relation) => + ({link: relation('linkTemplate')}), + + data: (path) => + ({path}), + + generate: (data, relations) => + relations.link + .slot('path', ['media.path', data.path]), +}; diff --git a/src/content/dependencies/linkPathFromRoot.js b/src/content/dependencies/linkPathFromRoot.js new file mode 100644 index 00000000..dab3ac1f --- /dev/null +++ b/src/content/dependencies/linkPathFromRoot.js @@ -0,0 +1,13 @@ +export default { + contentDependencies: ['linkTemplate'], + + relations: (relation) => + ({link: relation('linkTemplate')}), + + data: (path) => + ({path}), + + generate: (data, relations) => + relations.link + .slot('path', ['shared.path', data.path]), +}; diff --git a/src/content/dependencies/linkPathFromSite.js b/src/content/dependencies/linkPathFromSite.js new file mode 100644 index 00000000..64676465 --- /dev/null +++ b/src/content/dependencies/linkPathFromSite.js @@ -0,0 +1,13 @@ +export default { + contentDependencies: ['linkTemplate'], + + relations: (relation) => + ({link: relation('linkTemplate')}), + + data: (path) => + ({path}), + + generate: (data, relations) => + relations.link + .slot('path', ['localized.path', data.path]), +}; diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index 9a135eef..625b1374 100644 --- a/src/content/dependencies/transformContent.js +++ b/src/content/dependencies/transformContent.js @@ -129,9 +129,9 @@ const linkThingRelationMap = { }; const linkValueRelationMap = { - // media: 'linkPathFromMedia', - // root: 'linkPathFromRoot', - // site: 'linkPathFromSite', + media: 'linkPathFromMedia', + root: 'linkPathFromRoot', + site: 'linkPathFromSite', }; const linkIndexRelationMap = { -- cgit 1.3.0-6-gf8a5 From c1a2e63ba92e87002e5afaece21d5b11b07fd4f4 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 21:15:46 -0300 Subject: content: transformContent: fix [[date]] not working The implementation was basically all there, but replacerKey and replacerValue weren't being extracted from the tag node properly. --- src/content/dependencies/transformContent.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index 625b1374..ba66a02e 100644 --- a/src/content/dependencies/transformContent.js +++ b/src/content/dependencies/transformContent.js @@ -236,8 +236,16 @@ export default { } // This will be another {type: 'tag'} node which gets processed in - // generate. - return node; + // generate. Extract replacerKey and replacerValue now, since it'd + // be a pain to deal with later. + return { + ...node, + data: { + ...node.data, + replacerKey: node.data.replacerKey.data, + replacerValue: node.data.replacerValue[0].data, + }, + }; }), }; }, -- cgit 1.3.0-6-gf8a5 From b11444bf1ef1c111c39c7e898f08014f18e1139a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 21:20:25 -0300 Subject: content: transformContent: [[date]] use toUTCString --- src/content/dependencies/transformContent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index ba66a02e..848727db 100644 --- a/src/content/dependencies/transformContent.js +++ b/src/content/dependencies/transformContent.js @@ -33,7 +33,7 @@ export const replacerSpec = { value: (ref) => new Date(ref), html: (date, {html, language}) => html.tag('time', - {datetime: date.toString()}, + {datetime: date.toUTCString()}, language.formatDate(date)), }, 'flash-index': { -- cgit 1.3.0-6-gf8a5 From f484c6e9ea62baad8818864e715f8a435fddc241 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 21:24:55 -0300 Subject: We're Still Good(R) --- src/content/dependencies/transformContent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index a194e268..8494738c 100644 --- a/src/content/dependencies/transformContent.js +++ b/src/content/dependencies/transformContent.js @@ -385,7 +385,7 @@ export default { if (label) link.setSlot('content', label); if (hash) link.setSlot('hash', hash); - if (toIndex) { + if (!toIndex) { link.setSlot('preferShortName', slots.preferShortLinkNames); } -- cgit 1.3.0-6-gf8a5 From f9247a3a21abd26ae22d769d2da7d4ce6e99461d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 21:38:29 -0300 Subject: content: transformContent: "dynamically" detect slot availability --- src/content/dependencies/transformContent.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/content/dependencies') diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index 8494738c..93669cc1 100644 --- a/src/content/dependencies/transformContent.js +++ b/src/content/dependencies/transformContent.js @@ -189,14 +189,12 @@ export default { determineData: { // No value at all: this is an index link. 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; } @@ -214,7 +212,6 @@ export default { // Something was found: the link operates on that thing. data.thing = thing; - data.toIndex = false; } const {transformName} = spec; @@ -281,7 +278,6 @@ export default { link: relation(name, arg), label: node.data.label, hash: node.data.hash, - toIndex: node.data.toIndex, } : getPlaceholder(node, content)); @@ -376,7 +372,7 @@ export default { return {type: 'text', data: linkNode.data}; } - const {link, label, hash, toIndex} = linkNode; + const {link, label, hash} = linkNode; // These are removed from the typical combined slots({})-style // because we don't want to override slots that were already set @@ -385,7 +381,16 @@ export default { if (label) link.setSlot('content', label); if (hash) link.setSlot('hash', hash); - if (!toIndex) { + // TODO: This is obviously hacky. + let hasPreferShortNameSlot; + try { + link.getSlotDescription('preferShortName'); + hasPreferShortNameSlot = true; + } catch (error) { + hasPreferShortNameSlot = false; + } + + if (hasPreferShortNameSlot) { link.setSlot('preferShortName', slots.preferShortLinkNames); } -- cgit 1.3.0-6-gf8a5