Skip to content

Instantly share code, notes, and snippets.

@Akkiesoft
Created July 30, 2019 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akkiesoft/2435845c56dff958e210f1c59bb82c58 to your computer and use it in GitHub Desktop.
Save Akkiesoft/2435845c56dff958e210f1c59bb82c58 to your computer and use it in GitHub Desktop.
GitHubの特定ファイルのHistoryをRSS形式で出力するPHPスクリプト。PHPが動く適当なWebサーバーに置いてRSSとして購読して使う。
<?php
$title = "History for documentation/hardware/raspberrypi/conformity.md";
$url = "https://github.com/raspberrypi/documentation/commits/master/hardware/raspberrypi/conformity.md";
$description = $title;
$link_prefix = "https://github.com";
$html = file_get_contents($url);
$doc = new DOMDocument();
$doc->loadHTML($html);
$finder = new DomXPath($doc);
$out = "";
$commit = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' commit ')]");
foreach($commit as $item) {
$t = $item->getElementsByTagName('a')[0]->textContent;
$a = $item->getElementsByTagName('a')[2]->textContent;
$l = $link_prefix . $item->getElementsByTagName('a')[0]->getAttribute('href');
$d = date('r', strtotime($item->getElementsByTagName('relative-time')[0]->getAttribute('datetime')));
$out .= " <item><title>" . $t . "</title><link>" . $l . "</link><description>" . $a . "</description><pubDate>" . $d . "</pubDate></item>\n";
}
$out = '<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0"><channel><title>' . $title . "</title><link>" . $url . "</link><description>" . $description . "</description><language>en</language>\n" . $out;
$out .= "</channel></rss>";
header('Content-Type: application/xml');
print($out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment