jQuery Add Gist Embed from original Gist Link

问题描述

我想使用 jQuery 或 JavaScript 从原始 Gist 的链接自动添加 Gist Embed。例如:-

原始链接示例格式

https://gist.github.com/user/a3efe9bb4706aea8b6e63bcbe7eebaab

Gist Embed 的格式如 Github 所示,格式如下:-

<script src="https://gist.github.com/user/a3efe9bb4706aea8b6e63bcbe7eebaab.js"></script>

我希望代码做的是在容器 div '.post-content' 中搜索包含持久 URL 值的所有链接,即“https://gist.github.com/user/”,然后将完整 URL 作为脚本标签中的文本以最终确定嵌入格式。

到目前为止,我已经设法找到并检查匹配的 URL(gistLink 变量),但我不确定它是否会遍历每个 Github 链接,我还没有最终确定它添加到脚本标签中:-

<script>
jQuery(document).ready(function($) {
$('.post-content').each(function() {
var gistLink = $('a[href*="https://gist.github.com/user/"]').attr('href');
console.log(gistLink);
});
});
</script>

感谢您的意见。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)