diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/content/dependencies/linkPathFromMedia.js | 13 | ||||
-rw-r--r-- | src/content/dependencies/linkPathFromRoot.js | 13 | ||||
-rw-r--r-- | src/content/dependencies/linkPathFromSite.js | 13 | ||||
-rw-r--r-- | src/content/dependencies/linkTemplate.js | 6 | ||||
-rw-r--r-- | src/content/dependencies/linkThing.js | 13 | ||||
-rw-r--r-- | src/content/dependencies/transformContent.js | 57 | ||||
-rw-r--r-- | src/strings-default.json | 1 |
7 files changed, 87 insertions, 29 deletions
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/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/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) { diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index fef74e8c..93669cc1 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': { @@ -129,9 +129,9 @@ const linkThingRelationMap = { }; const linkValueRelationMap = { - // media: 'linkPathFromMedia', - // root: 'linkPathFromRoot', - // site: 'linkPathFromSite', + media: 'linkPathFromMedia', + root: 'linkPathFromRoot', + site: 'linkPathFromSite', }; const linkIndexRelationMap = { @@ -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; @@ -236,8 +233,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, + }, + }; }), }; }, @@ -273,7 +278,6 @@ export default { link: relation(name, arg), label: node.data.label, hash: node.data.hash, - toIndex: node.data.toIndex, } : getPlaceholder(node, content)); @@ -368,18 +372,29 @@ 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 + // by something that's wrapping the linkTemplate or linkThing + // template. + if (label) link.setSlot('content', label); + if (hash) link.setSlot('hash', hash); + + // TODO: This is obviously hacky. + let hasPreferShortNameSlot; + try { + link.getSlotDescription('preferShortName'); + hasPreferShortNameSlot = true; + } catch (error) { + hasPreferShortNameSlot = false; + } - return { - type: 'link', - data: - (toIndex - ? link.slots({content: label, hash}) - : link.slots({ - content: label, hash, - preferShortName: slots.preferShortLinkNames, - })), - }; + if (hasPreferShortNameSlot) { + link.setSlot('preferShortName', slots.preferShortLinkNames); + } + + return {type: 'link', data: link}; } case 'tag': { diff --git a/src/strings-default.json b/src/strings-default.json index 59e4a965..82a046f5 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", |