Skip to content

Commit 1776aad

Browse files
authored
Add comments to SPECs (#591)
* Add comments to SPECs * Sync with blog.sp.org version * Sync with blog.sp.org version * Show comments in correct location * Divide comments from rest of SPEC
1 parent 9294a6a commit 1776aad

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!-- Definitive version lives at https://github.com/scientific-python/blog.scientific-python.org -->
2+
{{ $page := . }}
3+
<hr/>
4+
<div id='discourse-comments'></div>
5+
<script type="text/javascript">
6+
// For an explanation of the flow of information here, see:
7+
// https://meta.discourse.org/t/automatic-dark-mode-for-embedded-comments-as-well/184347/19?u=stéfan_van_der_walt
8+
9+
const discourse_url = "https://discuss.scientific-python.org";
10+
11+
// Send a message to the iframe to let it know the dark/light mode choice
12+
const notifyIFrameOfTheme = () => {
13+
const iframe = document.getElementById("discourse-embed-frame");
14+
if (iframe && iframe.contentWindow) {
15+
iframe.contentWindow.postMessage(
16+
{
17+
theme: document.documentElement.getAttribute("data-theme")
18+
},
19+
discourse_url
20+
);
21+
}
22+
};
23+
24+
const observer = new MutationObserver((mutations) => {
25+
mutations.forEach((mutation) => {
26+
if (mutation.attributeName == "data-theme") {
27+
notifyIFrameOfTheme();
28+
}
29+
});
30+
31+
});
32+
observer.observe(document.querySelector("html"), {
33+
subtree: false,
34+
attributes: true,
35+
});
36+
37+
// Call notifyIFrameOfTheme once we receive a message from Discourse
38+
// that the comments iframe has loaded
39+
const handleMessageListener = (event) => {
40+
var origin = event.origin;
41+
if ((origin === discourse_url) && (event.data == "iframe loaded")) {
42+
notifyIFrameOfTheme();
43+
}
44+
};
45+
46+
// Call on Discourse to create a comment iframe
47+
// See https://meta.discourse.org/t/embed-discourse-comments-on-another-website-via-javascript/31963
48+
DiscourseEmbed = {
49+
discourseUrl: `${discourse_url}/`,
50+
{{ printf "discourseEmbedUrl: '%s'" $page.Permalink | safeJS }},
51+
// className: 'CLASS_NAME',
52+
};
53+
54+
(function () {
55+
var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
56+
d.src = `${DiscourseEmbed.discourseUrl}javascripts/embed.js`;
57+
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
58+
})();
59+
60+
window.addEventListener("message", handleMessageListener);
61+
</script>

layouts/specs/single.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ <h5 class="subtitle">{{ .Params.Subtitle }}</h5>
1111
{{- end }}
1212

1313
<div class="article-content">
14-
{{ .Content }}
14+
{{ .Content }}
15+
{{ partial "specs/comments.html" . }}
1516
</div>
1617
</div>
1718
{{ partial "shortcuts.html" . }}

0 commit comments

Comments
 (0)