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 +++++- src/strings-default.json | 1 + tap-snapshots/test/snapshot/linkTemplate.js.test.cjs | 8 ++++++-- test/snapshot/linkTemplate.js | 7 +++++++ 4 files changed, 19 insertions(+), 3 deletions(-) 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)); }, } diff --git a/src/strings-default.json b/src/strings-default.json index ec174a27..7987a9f6 100644 --- a/src/strings-default.json +++ b/src/strings-default.json @@ -197,6 +197,7 @@ "misc.external.flash.homestuck.page": "{LINK} (page {PAGE})", "misc.external.flash.homestuck.secret": "{LINK} (secret page)", "misc.external.flash.youtube": "{LINK} (on any device)", + "misc.missingLinkContent": "(Missing link content)", "misc.nav.previous": "Previous", "misc.nav.next": "Next", "misc.nav.info": "Info", diff --git a/tap-snapshots/test/snapshot/linkTemplate.js.test.cjs b/tap-snapshots/test/snapshot/linkTemplate.js.test.cjs index a9c1b678..e9d22ba5 100644 --- a/tap-snapshots/test/snapshot/linkTemplate.js.test.cjs +++ b/tap-snapshots/test/snapshot/linkTemplate.js.test.cjs @@ -10,9 +10,13 @@ exports[`test/snapshot/linkTemplate.js TAP linkTemplate (snapshot) > fill many s ` exports[`test/snapshot/linkTemplate.js TAP linkTemplate (snapshot) > fill path slot & provide appendIndexHTML 1`] = ` - +delish +` + +exports[`test/snapshot/linkTemplate.js TAP linkTemplate (snapshot) > missing content 1`] = ` +(Missing link content) ` exports[`test/snapshot/linkTemplate.js TAP linkTemplate (snapshot) > special characters in path argument 1`] = ` - +Damn, that's some good sheet music ` diff --git a/test/snapshot/linkTemplate.js b/test/snapshot/linkTemplate.js index 1db4582e..83d77108 100644 --- a/test/snapshot/linkTemplate.js +++ b/test/snapshot/linkTemplate.js @@ -30,6 +30,7 @@ testContentFunctions(t, 'linkTemplate (snapshot)', async (t, evaluate) => { slots: { path: ['myCoolPath', 'ham', 'pineapple', 'tomato'], + content: 'delish', }, }); @@ -41,6 +42,12 @@ testContentFunctions(t, 'linkTemplate (snapshot)', async (t, evaluate) => { 'homestuck-vol-1', 'Showtime (Piano Refrain) - #xXxAwesomeSheetMusick?rxXx#.pdf', ], + content: `Damn, that's some good sheet music`, }, }); + + evaluate.snapshot('missing content', { + name: 'linkTemplate', + slots: {href: 'banana'}, + }); }); -- 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(-) 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(-) 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 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(-) 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(-) 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 860453fa79802768ac0b4e19efa64d0be02ef66c Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 8 Aug 2023 21:20:47 -0300 Subject: test: transformContent (snapshot) - [[date]], [[string]] --- tap-snapshots/test/snapshot/transformContent.js.test.cjs | 11 +++++++++++ test/snapshot/transformContent.js | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/tap-snapshots/test/snapshot/transformContent.js.test.cjs b/tap-snapshots/test/snapshot/transformContent.js.test.cjs index 44535ec0..4b4e090f 100644 --- a/tap-snapshots/test/snapshot/transformContent.js.test.cjs +++ b/tap-snapshots/test/snapshot/transformContent.js.test.cjs @@ -5,6 +5,12 @@ * Make sure to inspect the output below. Do not ignore changes! */ 'use strict' +exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > dates 1`] = ` +

Yep!

+

Very nice:

+ +` + exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > inline images 1`] = `

as USUAL...

What do you know?

@@ -39,6 +45,11 @@ exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > non ` +exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > super basic string 1`] = ` +

Neat listing: Albums - by Date

+ +` + exports[`test/snapshot/transformContent.js TAP transformContent (snapshot) > two text paragraphs 1`] = `

Hello, world!

Wow, this is very cool.

diff --git a/test/snapshot/transformContent.js b/test/snapshot/transformContent.js index f55ca4fa..bf09a751 100644 --- a/test/snapshot/transformContent.js +++ b/test/snapshot/transformContent.js @@ -57,4 +57,12 @@ testContentFunctions(t, 'transformContent (snapshot)', async (t, evaluate) => { quickSnapshot( 'non-inline image #3', `\nBaller.`); + + quickSnapshot( + 'dates', + `[[date:2023-04-13]] Yep!\nVery nice: [[date:25 October 2413]]`); + + quickSnapshot( + 'super basic string', + `Neat listing: [[string:listingPage.listAlbums.byDate.title]]`); }); -- 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(-) 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(-) 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