Goal:
Load Postscribe, which will enable me to embed github gists into CMS collections per this blog post.
Steps to Recreate issue:
- Open up one Article (gists typically appear the first time, for some reason). ex: like this
- At the bottom in the “Recent Blog Posts” section, click on another Article, such as this one
- On this page, the gists don’t load:
Here’s the browser error:
live site: www.gregcondit.com
Here’s the relevant custom code which is copied into the footer code:
<!--Add Postscribe for displaying gists-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/postscribe/2.0.8/postscribe.min.js"></script>
<script>
// define the load gist function
var loadGist = function(elem) {
var gistUrl = $(elem).text().match(/\bhttps?:\/\/\S+(.js)/gi);
if (typeof gistUrl === 'undefined' || gistUrl === null || gistUrl.length == 0)
return;
//load gist
$(elem).show();
$(elem).empty();
postscribe(elem, '<script src=' + gistUrl+ '><\/script>');
};
var gists = $('p:contains("CODE:")');
gists.hide();
gists.toArray().forEach(loadGist);
</script>
How can I get this to load consistently?