6 Commits
v132 ... v138

6 changed files with 104 additions and 52 deletions

View File

@@ -4,3 +4,4 @@ d4733a95c3428db8722ce0d0350d17bbbabc8720 release-r72
7c92f9e2e4818d74eded59ad516d7d58b4072f8d release-r97 7c92f9e2e4818d74eded59ad516d7d58b4072f8d release-r97
b1426986ff5f265f79d6412c0e81ccc7cae652ff release-r118 b1426986ff5f265f79d6412c0e81ccc7cae652ff release-r118
2b11aaaad98718025d020c9fbaa451f65d413477 release-r126 2b11aaaad98718025d020c9fbaa451f65d413477 release-r126
36cb5fdcbd0450a32ba9e88f7582a78b0b50db94 release-r132

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.'/';
@@ -91,28 +92,41 @@ class CProject {
$this->longdesc $this->longdesc
); );
// Extract short description // Strip out any markdown image links
$parts = explode("\n", $this->longdesc); // [![](doc/image1.thumb.png)](doc/image1.png)
$this->shortdesc = array_shift($parts); $this->longdesc = preg_replace('~\\[!.+?\\)\\]\\(.+?\\)~m', '', $this->longdesc);
$this->shortdesc[0] = strtolower($this->shortdesc[0]); // cosmetic lowercase
// Filters for longdesc // Find "Written in" tags
$this->prefix_html = '';
$prefix_html = ''; $this->longdesc = preg_replace_callback('~\nWritten in ([^\\n]+)~ms', function($matches) {
$this->longdesc = preg_replace_callback('~\nWritten in ([^\\n]+)~ms', function($matches) use (&$prefix_html) { $this->prefix_html .= (
$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);
// Collapse multiple blank lines
$this->longdesc = ltrim($this->longdesc, "\n");
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; // Extract short description (last)
$parts = explode("\n", $this->longdesc);
$this->shortdesc = array_shift($parts);
$this->shortdesc[0] = strtolower($this->shortdesc[0]); // cosmetic lowercase
continue; continue;
} }

View File

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

View File

@@ -6,14 +6,16 @@ function template($title, $content, $extra_head='') {
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title><?=hesc($title)?></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<meta name="viewport" content="width=960" > <meta name="viewport" content="width=960" >
<?=$extra_head?> <?=$extra_head?>
<link rel="icon" href="<?=BASEURL?>static/favicon.ico" type="image/x-icon">
<link type="text/css" rel="stylesheet" href="<?=BASEURL?>static/normalize.css"> <link type="text/css" rel="stylesheet" href="<?=BASEURL?>static/normalize.css">
<link type="text/css" rel="stylesheet" href="<?=BASEURL?>static/style.css"> <link type="text/css" rel="stylesheet" href="<?=BASEURL?>static/style.css">
<script type="text/javascript" src="<?=BASEURL?>static/site.js"></script> <script type="text/javascript" src="<?=BASEURL?>static/site.js"></script>
<title><?=hesc($title)?></title>
</head> </head>
<body> <body>
<div id="container"> <div id="container">
@@ -194,3 +196,19 @@ function buildredirects($redirects) {
file_put_contents(BASEDIR.'wwwroot/'.$oldname.'/index.html', $page); 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

@@ -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);
@@ -109,6 +112,11 @@ function hesc($sz) {
return @htmlentities($sz, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); return @htmlentities($sz, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
} }
function mkdir_all($path) {
$epath = escapeshellarg($path);
`mkdir -p ${epath}`;
}
function text2html($sz) { function text2html($sz) {
$identity = function($sz) { $identity = function($sz) {
@@ -140,12 +148,19 @@ function text2html($sz) {
$base = preg_replace('~^=+(.+)=+~m', '<strong>\\1</strong>', $base); $base = preg_replace('~^=+(.+)=+~m', '<strong>\\1</strong>', $base);
$base = preg_replace('~\\[url=([^\\]]+?)\\](.+?)\\[/url\\]~m', '<a href="\\1">\\2</a>', $base); $base = preg_replace('~\\[url=([^\\]]+?)\\](.+?)\\[/url\\]~m', '<a href="\\1">\\2</a>', $base);
$base = preg_replace('~([^="])(https?://[^ \\r\\n\\t]+)~i', '\\1<a href="\\2">\\2</a>', $base);
$base = preg_replace('~\\[([^\\]]+?)\\]\\((https?://.+?)\\)~m', '<a href="\\2">\\1</a>', $base); // Support markdown-style URLs
$base = preg_replace('~([^="])(https?://[^ \\r\\n\\t]+)~i', '\\1<a href="\\2">\\2</a>', $base); // Support standalone URLs
$base = preg_replace('~\\[b\\](.+?)\\[/b\\]~m', '<strong>\\1</strong>', $base); $base = preg_replace('~\\[b\\](.+?)\\[/b\\]~m', '<strong>\\1</strong>', $base);
$base = preg_replace('~\\[i\\](.+?)\\[/i\\]~m', '<i>\\1</i>', $base); $base = preg_replace('~\\[i\\](.+?)\\[/i\\]~m', '<i>\\1</i>', $base);
$base = preg_replace('~\\[spoiler\\](.+?)\\[/spoiler\\]~m', '<span class="spoiler">\\1</span>', $base); $base = preg_replace('~\\[spoiler\\](.+?)\\[/spoiler\\]~m', '<span class="spoiler">\\1</span>', $base);
$base = preg_replace('~\n- ~ms', "\n&bull; ", $base); $base = preg_replace('~\n- ~ms', "\n&bull; ", $base);
$base = preg_replace('~^```.+$~m', '`', $base); // Convert ```html to single `{}` element
// TODO support markdown tables
$btparts = explode('`', $base); $btparts = explode('`', $base);
if (count($btparts) > 1 && (count($btparts) % 2)) { if (count($btparts) > 1 && (count($btparts) % 2)) {
for ($i = 1, $e = count($btparts); $i < $e; $i += 2) { for ($i = 1, $e = count($btparts); $i < $e; $i += 2) {
@@ -153,7 +168,7 @@ function text2html($sz) {
if (strpos($btparts[$i], "\n") !== false) { if (strpos($btparts[$i], "\n") !== false) {
$class .= ' code-multiline'; $class .= ' code-multiline';
} }
$btparts[$i] = '<span class="'.$class.'">'.$btparts[$i].'</span>'; $btparts[$i] = '<span class="'.$class.'">'.ltrim($btparts[$i], "\n").'</span>';
} }
} }

View File

@@ -9,44 +9,45 @@ numcpus() {
} }
buildsite() { buildsite() {
local site="$1"
echo "Site: ${1}" echo "Site: ${site}"
(
cd "$site"
pushd "$1" >/dev/null echo "Cleaning wwwroot directory..."
echo "Cleaning wwwroot directory..." if [[ -d wwwroot ]] ; then
rm -r wwwroot
if [[ -d wwwroot ]] ; then fi
rm -r wwwroot mkdir -p wwwroot/{img,srv,static}
fi
mkdir -p wwwroot/{img,srv,static}
echo "Copying static resources..."
if [[ ! -d static ]] ; then
mkdir static
fi
cp "${APP_DIR}/static/"* wwwroot/static || true
cp static/* wwwroot/static || true
for htm in footer header homepage_blurb ; do
if [[ ! -f "${htm}.htm" ]] ; then
touch "${htm}.htm"
fi
done
echo "Building pages..."
local threadcount=$(numcpus)
for i in $(seq 0 "$threadcount") ; do
"${APP_DIR}/lib/bootstrap.php" "$threadcount" "$i" &
done
wait
echo "Site: ${1} finished."
echo ""
popd >/dev/null echo "Copying static resources..."
if [[ ! -d static ]] ; then
mkdir static
fi
cp "${APP_DIR}/static/"* wwwroot/static || true
cp static/* wwwroot/static || true
for htm in footer header homepage_blurb ; do
if [[ ! -f "${htm}.htm" ]] ; then
touch "${htm}.htm"
fi
done
echo "Building pages..."
local threadcount=$(numcpus)
for i in $(seq 0 "$threadcount") ; do
"${APP_DIR}/lib/bootstrap.php" "$threadcount" "$i" &
done
wait
echo "Site: ${site} finished."
echo ""
)
} }
usage() { usage() {