replace 'written in' with a shields.io SVG

This commit is contained in:
mappu 2015-11-07 18:15:01 +13:00
parent 67f20f4379
commit f39a05ba59
2 changed files with 23 additions and 1 deletions

View File

@ -3,4 +3,4 @@ mode:regex
^sites/[^/]+/data/
^sites/[^/]+/wwwroot/
/_DRAFTS/
^shields_cache/

View File

@ -3,6 +3,21 @@
// Code-hosting website
// ````````````````````
function mkshield($left_str, $right_str, $color_str) {
$filename = rawurlencode(str_replace('-', '--', $left_str)).'-'.rawurlencode(str_replace('-', '--', $right_str)).'-'.rawurlencode($color_str).'.svg';
$cache_path = __DIR__.'/../../shields_cache/'.$filename;
if (file_exists($cache_path)) {
return file_get_contents($cache_path);
} else {
$retn = file_get_contents('https://img.shields.io/badge/'.$filename);
file_put_contents($cache_path, $retn);
return $retn;
}
}
/**
* Create a thumbnail of an image. It overscales, centers, and crops to fit the
* target dimensions.
@ -178,6 +193,7 @@ class CProject {
$this->lastupdate = max($this->lastupdate, filectime($this->dir.$file)); // don't count README updates
$this->longdesc = file_get_contents($this->dir.'README.txt');
$matches = array();
if (preg_match('~Written in ([^\\r\\n]+)~', $this->longdesc, $matches)) {
$this->subtag = rtrim($matches[1], ' .');
@ -190,6 +206,12 @@ class CProject {
$parts = explode("\n", $this->longdesc);
$this->shortdesc = array_shift($parts);
$this->shortdesc[0] = strtolower($this->shortdesc[0]); // cosmetic lowercase
// Filter longdesc
$this->longdesc = preg_replace_callback('~Written in ([^\\r\\n]+)~', function($matches) {
return '<html>'.mkshield('written in', $matches[1], 'blue').'</html>';
}, $this->longdesc);
continue;
}