diff --git a/src/utils/twitter.ts b/src/utils/twitter.ts new file mode 100644 index 0000000..540912f --- /dev/null +++ b/src/utils/twitter.ts @@ -0,0 +1,43 @@ +// @ts-nocheck + +// https://github.com/rlidwka/markdown-it-regexp +/* +const texte = "@[tweet](21345)"; +const regex = /@\[tweet]\((.*?)\)/; +const resultat = regex.exec(texte)[1]; +console.log(resultat); +*/ + +window.twttr = (function (d, s, id) { + let js, + fjs = d.getElementsByTagName(s)[0], + t = window.twttr || {} + + if (d.getElementById(id)) { + return t + } + + js = d.createElement(s) + js.id = id + js.src = 'https://platform.twitter.com/widgets.js' + fjs.parentNode.insertBefore(js, fjs) + + t._e = [] + t.ready = (f) => { + t._e.push(f) + } + + return t +})(document, 'script', 'twitter-lite-note') + +export const createTweet = ( + tweetId: string, + theme: 'light' | 'dark' = 'light' +) => { + window.twttr.ready(() => { + window.twttr.widgets.createTweet( + tweetId, + document.getElementById(`tweet-${tweetId}`, { theme }) + ) + }) +} diff --git a/src/views/SpacedRepetitionCard.vue b/src/views/SpacedRepetitionCard.vue index 28afbf1..12b0a63 100644 --- a/src/views/SpacedRepetitionCard.vue +++ b/src/views/SpacedRepetitionCard.vue @@ -26,6 +26,7 @@ const firstCard = computed(() => { :repo="repo" :with-content="false" > +
Loading...

Level: {{ firstCard.repetition.level }}