From 75aa3ffb8df9fd5d9a20a685239416e58cef7626 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sat, 9 Sep 2017 21:20:59 +0200 Subject: [PATCH] grab author metadata from one source --- _src/_assets/js/_modals.js | 33 +++++++++++++++++++++++++-------- _src/api/site.json | 7 +++++-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/_src/_assets/js/_modals.js b/_src/_assets/js/_modals.js index 04274e95..67ffbb96 100644 --- a/_src/_assets/js/_modals.js +++ b/_src/_assets/js/_modals.js @@ -2,7 +2,7 @@ // Vex modals // -/* global vex */ +/* global vex, fetch */ /* exported krlcModals */ /* eslint-disable spaced-comment */ @@ -11,25 +11,42 @@ const krlcModals = (() => { // eslint-disable-line no-unused-vars const _config = { - vexTriggers: document.querySelectorAll('.js-vex-btc'), - modalContent: '

My Bitcoin Address

\n \n
171qDmKEXm9YBgBLXyGjjPvopP5o9htQ1V
' + btcVexTriggers: document.querySelectorAll('.js-vex-btc') } + let btcAddress + const _private = { - initVex() { - _config.vexTriggers.forEach(el => { + getBtcAddress() { + const url = '/api/site.json' + + fetch(url) + .then(res => res.json()) + .then(data_ => { + btcAddress = data_[0].author.bitcoin + }) + .catch(err => console.error(err)) + + return btcAddress + }, + + vexBtc() { + _config.btcVexTriggers.forEach(el => { el.addEventListener('click', e => { e.preventDefault() vex.defaultOptions.className = 'vex-theme-kremalicious vex-bitcoin' vex.dialog.buttons.YES.text = 'Close' - vex.open({unsafeContent: _config.modalContent}) - }, false) + vex.open({unsafeContent: '

My Bitcoin Address

\n \n
' + btcAddress + '
'}) + }) }) } } return { - init: _private.initVex + init() { + _private.getBtcAddress() + _private.vexBtc() + } } })(); // eslint-disable-line semi diff --git a/_src/api/site.json b/_src/api/site.json index e95267d3..b9015cfb 100644 --- a/_src/api/site.json +++ b/_src/api/site.json @@ -1,10 +1,13 @@ --- -layout: null --- [ { "name" : "{{ site.name }}", "description" : "{{ site.description | xml_escape }}", - "url" : "{{ site.url }}" + "url" : "{{ site.url }}", + "author" : { + {% for item in site.author %}"{{ item[0] }}": "{{ item[1] }}"{% unless forloop.last %},{% endunless %} + {% endfor %} + } } ]