I want to use jQuery or JavaScript to automatically add a Gist Embed from a link for the original Gist. For example:-
Original Link Example Format
https://gist.github.com/user/a3efe9bb4706aea8b6e63bcbe7eebaab
Format for Gist Embed as shown on Github would be of the format:-
<script src="https://gist.github.com/user/a3efe9bb4706aea8b6e63bcbe7eebaab.js"></script>
What I want the code to do is search through a container div '.post-content' for all links that include the persistent URL value i.e. 'https://gist.github.com/user/' and then wrap the full URL as text in the script tags to finalise the embed format.
So far I have managed to find and check for matching URL (gistLink variable), but I'm not sure if it would iterate through each and every Github link and I haven't finalised it to add in the script tags either:-
<script>
jQuery(document).ready(function($) {
$('.post-content').each(function() {
var gistLink = $('a[href*="https://gist.github.com/user/"]').attr('href');
console.log(gistLink);
});
});
</script>
Your input is appreciated.
Thanks
question from:https://stackoverflow.com/questions/65945423/jquery-add-gist-embed-from-original-gist-link