将GitHub文件包含在远程网站中

时间:2012-04-15 15:07:00

标签: api github

将GitHub README.md文件嵌入远程网站的简单方法是什么?

我希望在网页上拥有README文件的同步副本,我认为GitHub页面不允许用户这样做,我在GitHub API中找不到答案。有什么想法吗?

3 个答案:

答案 0 :(得分:1)

如果您需要像example.com/project/README.md中的文件副本或php页面上显示的内容,则取决于您想要的副本类型。如果您想要的是第一个,您可以制作一个PHP脚本来获取文件到您的服务器。但是如果你想在php页面上拥有它,你可以使用类似的东西:

<?php
$url = "https://raw.github.com/USER/PROJECT/README.md";
$readme = file_get_contents($url);

print $readme;
?>

这就是我之前提到的fetch脚本

<?php
$url = "https://raw.github.com/USER/PROJECT/README.md";
$readme = file_get_contents($url);

$file = fopen('README.md','w');
fputs("$file","$readme");
fclose($file);
?>

答案 1 :(得分:1)

查看http://developer.github.com/v3/git/blobs/

您可以检索和创建blob。

答案 2 :(得分:1)

这可以解决我的问题: Using the GitHub API and PHP to Get Repository Information here是一个有效的演示。

相关问题