support go subpackages

This commit is contained in:
mappu 2017-10-29 14:15:00 +13:00
parent 8a43a8181e
commit fb20358834
3 changed files with 24 additions and 0 deletions

View File

@ -46,6 +46,9 @@ function main($args) {
if (array_key_exists('redirect', $config)) {
buildredirects( $config['redirect'] );
}
if (array_key_exists('golang-subpackages', $config)) {
buildgosubpackages( $config['golang-subpackages'] );
}
} else {
buildprojects($pos, array_decimate(listprojects(), $total, $pos));
}

View File

@ -194,3 +194,19 @@ function buildredirects($redirects) {
file_put_contents(BASEDIR.'wwwroot/'.$oldname.'/index.html', $page);
}
}
function buildgosubpackages($packages) {
foreach($packages as $path => $goGetStr) {
$page = (
'<meta name="go-import" content="'.hesc($goGetStr).'">'.
"\n".
redirecthtml(BASEURL)
);
// new directory format only
mkdir_all(BASEDIR.'wwwroot/'.$path);
file_put_contents(BASEDIR.'wwwroot/'.$path.'/index.html', $page);
}
}

View File

@ -109,6 +109,11 @@ function hesc($sz) {
return @htmlentities($sz, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
function mkdir_all($path) {
$epath = escapeshellarg($path);
`mkdir -p ${epath}`;
}
function text2html($sz) {
$identity = function($sz) {