Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 52f90c5673 | |||
| 428303c9fb | |||
| 4811fcc29e | |||
| ff70556d8e | |||
| fb20358834 | |||
| 8a43a8181e | |||
| 2e9666521b | |||
| b75ec5aba8 | |||
| 657d5ccd31 | |||
| 5801030e31 | |||
| 8adadb0be1 |
2
.hgtags
2
.hgtags
@@ -3,3 +3,5 @@
|
|||||||
d4733a95c3428db8722ce0d0350d17bbbabc8720 release-r72
|
d4733a95c3428db8722ce0d0350d17bbbabc8720 release-r72
|
||||||
7c92f9e2e4818d74eded59ad516d7d58b4072f8d release-r97
|
7c92f9e2e4818d74eded59ad516d7d58b4072f8d release-r97
|
||||||
b1426986ff5f265f79d6412c0e81ccc7cae652ff release-r118
|
b1426986ff5f265f79d6412c0e81ccc7cae652ff release-r118
|
||||||
|
2b11aaaad98718025d020c9fbaa451f65d413477 release-r126
|
||||||
|
36cb5fdcbd0450a32ba9e88f7582a78b0b50db94 release-r132
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ Written in PHP, Bash
|
|||||||
|
|
||||||
=CHANGELOG=
|
=CHANGELOG=
|
||||||
|
|
||||||
|
2017-10-28: v132
|
||||||
|
- Fix an issue with not applying project rename redirections in the new URL format
|
||||||
|
- Fix a cosmetic issue with classifying downloads named with numeric strings
|
||||||
|
- Fix a cosmetic issue with truncated sheilds caused by ID collisions
|
||||||
|
|
||||||
2017-04-23: v126
|
2017-04-23: v126
|
||||||
- Breaking: BASEURL is now a mandatory field
|
- Breaking: BASEURL is now a mandatory field
|
||||||
- Feature: Support `[go-get]` tags
|
- Feature: Support `[go-get]` tags
|
||||||
|
|||||||
@@ -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.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 .= ' ';
|
||||||
|
}
|
||||||
|
$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;
|
||||||
}
|
}
|
||||||
@@ -196,7 +210,7 @@ class CProject {
|
|||||||
}
|
}
|
||||||
foreach($this->downloads as $idx => $filename) {
|
foreach($this->downloads as $idx => $filename) {
|
||||||
foreach(array_keys($known_tags) as $tagname) {
|
foreach(array_keys($known_tags) as $tagname) {
|
||||||
if (stripos($filename, $tagname) !== false) {
|
if (stripos($filename, (string)$tagname) !== false) {
|
||||||
$found_idx[$idx] = $tagname;
|
$found_idx[$idx] = $tagname;
|
||||||
|
|
||||||
$render_per_tag[$tagname][$idx] = $filename;
|
$render_per_tag[$tagname][$idx] = $filename;
|
||||||
|
|||||||
@@ -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));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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">
|
||||||
@@ -183,7 +185,30 @@ function redirecthtml($target) {
|
|||||||
|
|
||||||
function buildredirects($redirects) {
|
function buildredirects($redirects) {
|
||||||
foreach($redirects as $oldname => $newname) {
|
foreach($redirects as $oldname => $newname) {
|
||||||
$page = redirecthtml($newname.'.html');
|
|
||||||
|
$page = redirecthtml(BASEURL.$newname.'/');
|
||||||
|
|
||||||
|
// old format
|
||||||
file_put_contents(BASEDIR.'wwwroot/'.$oldname.'.html', $page);
|
file_put_contents(BASEDIR.'wwwroot/'.$oldname.'.html', $page);
|
||||||
|
|
||||||
|
// new format
|
||||||
|
mkdir(BASEDIR.'wwwroot/'.$oldname);
|
||||||
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
lib/util.php
29
lib/util.php
@@ -1,20 +1,29 @@
|
|||||||
<?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);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$retn = file_get_contents('https://img.shields.io/badge/'.$filename);
|
$retn = file_get_contents('https://img.shields.io/badge/'.$filename);
|
||||||
|
|
||||||
|
// We need unique IDs
|
||||||
|
$prefix = substr(sha1($filename), 8).'-';
|
||||||
|
$retn = str_replace('id="', 'id="'.$prefix, $retn);
|
||||||
|
$retn = str_replace('url(#', 'url(#'.$prefix, $retn);
|
||||||
|
|
||||||
file_put_contents($cache_path, $retn);
|
file_put_contents($cache_path, $retn);
|
||||||
return $retn;
|
return $retn;
|
||||||
|
|
||||||
@@ -103,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) {
|
||||||
@@ -134,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• ", $base);
|
$base = preg_replace('~\n- ~ms', "\n• ", $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) {
|
||||||
@@ -147,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>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
69
rebuild.sh
69
rebuild.sh
@@ -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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user