From ae17a586abf9b807a1b1603132f9af3e3d95477b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= <postmaster@greg0ire.fr>
Date: Tue, 20 Mar 2018 11:15:32 +0100
Subject: [PATCH] Add script to embed tweets properly

---
 embed-tweet.js | 43 +++++++++++++++++++++++++++++++++++++++++++
 index.md       |  4 ++--
 package.json   |  4 ++--
 3 files changed, 47 insertions(+), 4 deletions(-)
 create mode 100644 embed-tweet.js

diff --git a/embed-tweet.js b/embed-tweet.js
new file mode 100644
index 0000000..7922778
--- /dev/null
+++ b/embed-tweet.js
@@ -0,0 +1,43 @@
+var RevealEmbedTweet = window.RevealEmbedTweet || (function(){
+	var ready = false;
+	window.twttr = (function(d, s, id) {
+		var 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 = function(f) {
+				t._e.push(f);
+		};
+	}(document, "script", "twitter-wjs"));
+
+
+	function load() {
+		if ( twttr != undefined && !document.querySelector('section[data-markdown]:not([data-markdown-parsed])') ) {
+			tweets = document.querySelectorAll(".tweet");
+			for (i = 0; i < tweets.length; ++i) {
+				tweets[i].style.cssText = "margin: 0;position: absolute; left: 50%;transform: translate(-50%,0%);" + tweets[i].style.cssText;
+				tweets[i].innerHTML = 	'<blockquote class="twitter-tweet" data-lang="en"><a href="' + tweets[i].getAttribute('data-src') + '">Tweet</a></blockquote>';
+			}
+			twttr.widgets.load()
+		}
+		else {
+			// wait for markdown to be loaded and parsed
+			setTimeout( load, 100 );
+		}
+	}
+
+	Reveal.addEventListener( 'ready', function( event ) {
+		load();
+	} );
+
+
+})();
+
+
+
+
diff --git a/index.md b/index.md
index 1e9018f..a5dc8d5 100644
--- a/index.md
+++ b/index.md
@@ -67,8 +67,8 @@ Notes:
 
 
 ---
-<blockquote class="twitter-tweet" data-lang="fr"><p lang="en" dir="ltr"><a href="https://twitter.com/hashtag/doctrine3?src=hash&amp;ref_src=twsrc%5Etfw">#doctrine3</a> docs now differentiate between anemic and rich entities! \o/<a href="https://t.co/cL00Ilh0DX">https://t.co/cL00Ilh0DX</a><br><br>Thanks <a href="https://twitter.com/Pierstoval?ref_src=twsrc%5Etfw">@Pierstoval</a>!</p>&mdash; �̥͙͔͓͙͇̙�̷̫̱͎͖�͉�͓̮̥�̛̳̙̗͍�̴̺ (@Ocramius) <a href="https://twitter.com/Ocramius/status/975399920202080256?ref_src=twsrc%5Etfw">18 mars 2018</a></blockquote>
-<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
+
+<div class="tweet" data-src="https://twitter.com/Ocramius/status/975399920202080256"></div>
 
 
 ---
diff --git a/package.json b/package.json
index f6f0c10..52d625c 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
     "reveal-md": "^1.1.3"
   },
   "scripts": {
-    "start": "reveal-md index.md --port 8000 --theme=solarized --css hello.css",
-    "build": "reveal-md index.md --static _site --theme=solarized --css hello.css"
+    "start": "reveal-md index.md --port 8000 --theme=solarized --css hello.css --scripts embed-tweet.js",
+    "build": "reveal-md index.md --static _site --theme=solarized --css hello.css --scripts embed-tweet.js"
   }
 }
-- 
GitLab