support linking to custom go repositories

This commit is contained in:
mappu 2018-12-30 13:50:39 +13:00
parent fb20358834
commit ff70556d8e
2 changed files with 19 additions and 7 deletions

View File

@ -25,6 +25,7 @@ class CProject {
public $homeimage = null; public $homeimage = null;
protected $go_get_target = ''; protected $go_get_target = '';
protected $git_repo = '';
public function __construct($dirname, $projname) { public function __construct($dirname, $projname) {
$this->dir = BASEDIR.'data/'.$dirname.'/'; $this->dir = BASEDIR.'data/'.$dirname.'/';
@ -98,21 +99,29 @@ class CProject {
// Filters for longdesc // Filters for longdesc
$prefix_html = ''; $this->prefix_html = '';
$this->longdesc = preg_replace_callback('~\nWritten in ([^\\n]+)~ms', function($matches) use (&$prefix_html) { $this->longdesc = preg_replace_callback('~\nWritten in ([^\\n]+)~ms', function($matches) {
$prefix_html .= ( $this->prefix_html .= (
(SHIELDS_PREFIX ? mkshield('build', 'success', 'brightgreen').' ' : ''). (SHIELDS_PREFIX ? mkshield('build', 'success', 'brightgreen').' ' : '').
mkshield('written in', rtrim($matches[1], '.'), 'blue') mkshield('written in', rtrim($matches[1], '.'), 'blue')
); );
return ''; return '';
}, $this->longdesc); }, $this->longdesc);
// Find 'git-repository' tags
$this->longdesc = preg_replace_callback('~\[git\](.+)\[/git\]~', function($matches) {
$this->git_repo = $matches[1];
if (strlen($this->prefix_html) > 0) {
$this->prefix_html .= '&nbsp';
}
$this->prefix_html .= '<a href="'.hesc($this->git_repo).'">'.mkshield('vcs', 'git', 'yellowgreen', ['logo' => 'git']).'</a>';
return '';
}, $this->longdesc);
while(strpos($this->longdesc, "\n\n\n") !== false) { while(strpos($this->longdesc, "\n\n\n") !== false) {
$this->longdesc = str_replace("\n\n\n", "\n\n", $this->longdesc); $this->longdesc = str_replace("\n\n\n", "\n\n", $this->longdesc);
} }
$this->longdesc = rtrim($this->longdesc, "\n")."\n"; $this->longdesc = rtrim($this->longdesc, "\n")."\n";
$this->prefix_html = $prefix_html;
continue; continue;
} }

View File

@ -1,14 +1,17 @@
<?php <?php
function mkshield($left_str, $right_str, $color_str) { function mkshield($left_str, $right_str, $color_str, $params=[]) {
$filename = sprintf( $filename = sprintf(
"%s-%s-%s.svg", "%s-%s-%s.svg",
rawurlencode(str_replace('-', '--', $left_str)), rawurlencode(str_replace('-', '--', $left_str)),
rawurlencode(str_replace('-', '--', $right_str)), rawurlencode(str_replace('-', '--', $right_str)),
rawurlencode($color_str) rawurlencode($color_str)
); );
if (count($params) > 0) {
$filename .= '?' . http_build_query($params);
}
$cache_path = SHIELDS_CACHE_DIR.$filename; $cache_path = SHIELDS_CACHE_DIR.urlencode($filename);
if (file_exists($cache_path)) { if (file_exists($cache_path)) {
return file_get_contents($cache_path); return file_get_contents($cache_path);