It works great, and renders much more nicely than using the “native” Webflow embed feature. But for some reason doesn’t work specifically for Github Gists, which is used frequently on a client blog I am working on. So I went ahead and followed this tutorial (via oyemike) specifically for 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>
Which also works great, however for some reason the Gists are rendering twice, assumably something to do with the two pieces of custom code working together?
Would someone be able to help me in fixing this issue? Perhaps there’s a way to combine the two custom code pieces? Any help would be greatly appreciated.
Update: After a bit of trial and error, I managed to fix the issue by keeping the Github Gists custom code in the global custom code section, but moving the other custom code (for general embeds) in to the page-specific custom code section (both in the footer part). Maybe this has something to do with the order in which the code is read by web browsers?
Honestly I don’t know enough to really know how it fixed the issue, or how “stable” the fix is, so for now I will just keep my eye on it.
Unfortunately after more editing of the site in general, the duplicated Gists issue is coming back. It seems to be a bit temperamental, sometimes I can remove the custom code, publish, add the custom code back, publish, and it fixes the issue. But then if I make a change (elsewhere on the site) and publish the changes, the issue comes back, even if the I was working on a completely different part of the site.
If anyone with coding knowledge could help that would be awesome!
I prefer to embed the variable part of the custom code in a CMS item field, then include it. This way I don’t need to force the client to make an external connection (except for the CDN script i use).
I had a look at the article you sent through Jeff, but unfortunately that approach won’t work for me as this all needs to be controlled in a single rich text element for the client to add/edit blog posts easily.
@samliew I noticed you helped edit the custom code from Ohn originally, perhaps you know a way to combine the two so that gists work (and are not rendered twice on the page)?
Also I don’t usually like to rant, but I would like to add that it seems a real shame that we need to find these workarounds anyway. If Webflow’s native embed rendering for Twitter/Instagram etc wasn’t so broken (especially on mobile) I would’t be having these issues in the first place I could just use the custom code for Github Gists (which works perfectly on its own) and let Webflow handle the rest. Rant over!
Yes! I saw the announcement for this while I was away on holiday and haven’t had a chance to test it out yet, but I think this should solve the problem I was facing