From 53eb9d679e9b43f59320b39a52421cb33a15f9de Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 15 Oct 2024 23:18:02 -0300 Subject: content, client: generateIntrapageDotSwitcher --- .../dependencies/generateIntrapageDotSwitcher.js | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/content/dependencies/generateIntrapageDotSwitcher.js (limited to 'src/content') 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))), + }), +}; -- cgit 1.3.0-6-gf8a5