diff options
Diffstat (limited to 'src/content/dependencies/linkTemplate.js')
-rw-r--r-- | src/content/dependencies/linkTemplate.js | 92 |
1 files changed, 43 insertions, 49 deletions
diff --git a/src/content/dependencies/linkTemplate.js b/src/content/dependencies/linkTemplate.js index 9109ab50..98e2c8b9 100644 --- a/src/content/dependencies/linkTemplate.js +++ b/src/content/dependencies/linkTemplate.js @@ -8,66 +8,60 @@ export default { 'to', ], - generate({ + slots: { + href: {type: 'string'}, + path: {validate: v => v.validateArrayItems(v.isString)}, + hash: {type: 'string'}, + + tooltip: {validate: v => v.isString}, + attributes: {validate: v => v.isAttributes}, + color: {validate: v => v.isColor}, + content: {type: 'html'}, + }, + + generate(slots, { appendIndexHTML, getColors, html, to, }) { - return html.template({ - annotation: 'linkTemplate', - - slots: { - href: {type: 'string'}, - path: {validate: v => v.validateArrayItems(v.isString)}, - hash: {type: 'string'}, - - tooltip: {validate: v => v.isString}, - attributes: {validate: v => v.isAttributes}, - color: {validate: v => v.isColor}, - content: {type: 'html'}, - }, - - content(slots) { - let href = slots.href; - let style; - let title; + let href = slots.href; + let style; + let title; - if (!href && !empty(slots.path)) { - href = to(...slots.path); - } + if (!href && !empty(slots.path)) { + href = to(...slots.path); + } - if (appendIndexHTML) { - if ( - /^(?!https?:\/\/).+\/$/.test(href) && - href.endsWith('/') - ) { - href += 'index.html'; - } - } + if (appendIndexHTML) { + if ( + /^(?!https?:\/\/).+\/$/.test(href) && + href.endsWith('/') + ) { + href += 'index.html'; + } + } - if (slots.hash) { - href += (slots.hash.startsWith('#') ? '' : '#') + slots.hash; - } + if (slots.hash) { + href += (slots.hash.startsWith('#') ? '' : '#') + slots.hash; + } - if (slots.color) { - const {primary, dim} = getColors(slots.color); - style = `--primary-color: ${primary}; --dim-color: ${dim}`; - } + if (slots.color) { + const {primary, dim} = getColors(slots.color); + style = `--primary-color: ${primary}; --dim-color: ${dim}`; + } - if (slots.tooltip) { - title = slots.tooltip; - } + if (slots.tooltip) { + title = slots.tooltip; + } - return html.tag('a', - { - ...slots.attributes ?? {}, - href, - style, - title, - }, - slots.content); + return html.tag('a', + { + ...slots.attributes ?? {}, + href, + style, + title, }, - }); + slots.content); }, } |