diff options
Diffstat (limited to 'src/content/dependencies/linkThing.js')
-rw-r--r-- | src/content/dependencies/linkThing.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/content/dependencies/linkThing.js b/src/content/dependencies/linkThing.js new file mode 100644 index 00000000..ebff6761 --- /dev/null +++ b/src/content/dependencies/linkThing.js @@ -0,0 +1,51 @@ +import {empty} from '../../util/sugar.js'; + +export default { + contentDependencies: [ + 'linkTemplate', + ], + + extraDependencies: [ + 'html', + ], + + relations(relation) { + return { + linkTemplate: relation('linkTemplate'), + }; + }, + + data(pathKey, thing) { + return { + pathKey, + + color: thing.color, + directory: thing.directory, + + name: thing.name, + nameShort: thing.nameShort, + }; + }, + + generate(data, relations, {html}) { + const path = [data.pathKey, data.directory]; + + return html.template(slot => + slot('content', ([...content]) => + slot('preferShortName', ([preferShortName]) => { + if (empty(content)) { + content = + (preferShortName + ? data.nameShort ?? data.name + : data.name); + } + + return relations.linkTemplate + .slot('path', path) + .slot('color', slot('color', data.color)) + .slot('attributes', slot('attributes', {})) + .slot('hash', slot('hash')) + .slot('content', content); + }))); + }, +} |