diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-10-15 23:18:02 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-11-02 22:12:48 -0300 |
commit | 53eb9d679e9b43f59320b39a52421cb33a15f9de (patch) | |
tree | 25ee1742a8558494097f37d37222d59ca70a1140 /src/content/dependencies | |
parent | b657f641c89ceee7676dc6d29fe4b9a168a97266 (diff) |
content, client: generateIntrapageDotSwitcher
Diffstat (limited to 'src/content/dependencies')
-rw-r--r-- | src/content/dependencies/generateIntrapageDotSwitcher.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/content/dependencies/generateIntrapageDotSwitcher.js b/src/content/dependencies/generateIntrapageDotSwitcher.js new file mode 100644 index 00000000..3f300676 --- /dev/null +++ b/src/content/dependencies/generateIntrapageDotSwitcher.js @@ -0,0 +1,47 @@ +import {stitchArrays} from '#sugar'; + +export default { + contentDependencies: ['generateDotSwitcherTemplate'], + extraDependencies: ['html', 'language'], + + relations: (relation) => ({ + template: + relation('generateDotSwitcherTemplate'), + }), + + slots: { + attributes: { + type: 'attributes', + mutable: false, + }, + + initialOptionIndex: {type: 'number'}, + + titles: { + validate: v => v.strictArrayOf(v.isHTML), + }, + + targetIDs: { + validate: v => v.strictArrayOf(v.isString), + }, + }, + + generate: (relations, slots, {html, language}) => + relations.template.slots({ + attributes: [ + {class: 'intrapage'}, + slots.attributes, + ], + + initialOptionIndex: slots.initialOptionIndex, + + options: + stitchArrays({ + title: slots.titles, + targetID: slots.targetIDs, + }).map(({title, targetID}) => + html.tag('a', {href: '#'}, + {'data-target-id': targetID}, + language.sanitize(title))), + }), +}; |