简体   繁体   English

如何将Github中的代码添加到Codepen项目中?

[英]How can I add code from Github into my Codepen project?

I've got a repository with some code that I'd like to incorporate into my Codepen project, however I have no idea how. 我有一个存储库,其中包含一些要合并到Codepen项目中的代码,但是我不知道该怎么做。

What I'm trying to do is get 10 million digits of pi as a variable to use in my project. 我想做的是获取pi的一千万位数作为变量,以便在我的项目中使用。

Right now my project takes the variable pieIsGood from another Codepen using Ajax using this code: 现在,我的项目使用以下代码从使用Ajax的另一个Codepen中获取变量pieIsGood:

 $.getJSON('http://codepen.io/creativekinetix/pen/PpOOrE.js',jsonLoaded);
var pieIsGood;
function jsonLoaded(data) {
  pieIsGood = data.pi;
  pieIsGood = pieIsGood.toString()
}

Although this code works, Codepen only allows pens of a certain length (I think it tops out around a million characters). 尽管此代码有效,但Codepen仅允许使用一定长度的笔(我认为它最多可以写一百万个字符)。 I'd like to find a way to either use the code from this Github gist or this website and turn it into variable pieIsGood to use in my project. 我想找到一种方法来使用来自Github要点此网站的代码,并将其转换为变量pieIsGood以在我的项目中使用。 I can't use Ajax because anything I do there has to be in the same domain, and Codepen doesn't allow 10 million digits of pi. 我不能使用Ajax,因为我在那做的任何事情都必须在同一个域中,而Codepen不允许使用一千万位pi。

Since codepen doesn't allow me to post three links with my current reputation level, here's the broken link. 由于Codepen不允许我发布三个具有当前信誉级别的链接,因此这是断开的链接。 It just needs a : after the http. 它只需要在http之后加上一个:即可。

http://codepen.io/Random_Pseudonym/pen/EWvdge http://codepen.io/Random_Pseudonym/pen/EWvdge

Any help is greatly appreciated (I've spent something like ten hours trying to find a solution, I'd be ridiculously grateful to have it solved!) 非常感谢您的帮助(我花了大约十个小时尝试寻找解决方案,非常感激能解决这个问题!)

You can store a JSON file in a gist, for instance this one and include the raw URL in you Ajax request : 您可以将JSON文件存储在一个要点中,例如文件,并将原始URL包含在您的Ajax请求中:

$.getJSON('https://gist.githubusercontent.com/bertrandmartel/f8936fcffe7d3fec8c85782f60fd77e9/raw/86e4fce24116005f2748aeacdb5e94624937eb31/pi_digits.json',jsonLoaded);
var pieIsGood;
function jsonLoaded(data) {
  pieIsGood = data.pi;
  console.log(pieIsGood);
}

You can find a live example here 您可以在此处找到一个实时示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM