Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9af6849a82 | |||
| 650664a95d | |||
| 6c21f36d77 | |||
| 378dbec981 | |||
| b10e5696e2 | |||
| f05f429728 | |||
| d9b52860b6 | |||
| 242f69c731 | |||
| 1a0191a716 |
1
.hgtags
1
.hgtags
@@ -2,3 +2,4 @@
|
||||
0f89ae041c2ee60cc1ea308d047fce816b19c490 release-r64
|
||||
d4733a95c3428db8722ce0d0350d17bbbabc8720 release-r72
|
||||
7c92f9e2e4818d74eded59ad516d7d58b4072f8d release-r97
|
||||
b1426986ff5f265f79d6412c0e81ccc7cae652ff release-r118
|
||||
|
||||
@@ -14,6 +14,14 @@ Written in PHP, Bash
|
||||
|
||||
=CHANGELOG=
|
||||
|
||||
2017-04-23: v126
|
||||
- Breaking: BASEURL is now a mandatory field
|
||||
- Feature: Support `[go-get]` tags
|
||||
- Feature: Canonical paths for SEO
|
||||
- Feature: Use extension-less paths by default (old .html paths still supported via redirect)
|
||||
- Feature: Support `[url]` tags
|
||||
- Enhancement: Cache-busting parameters on homepage thumbnails
|
||||
|
||||
2016-04-19: v118
|
||||
- Feature: Classify download artefacts by matching CHANGELOG entry
|
||||
- Feature: Allow sorting by lifespan, artefacts, release entries
|
||||
|
||||
@@ -24,6 +24,8 @@ class CProject {
|
||||
|
||||
public $homeimage = null;
|
||||
|
||||
protected $go_get_target = '';
|
||||
|
||||
public function __construct($dirname, $projname) {
|
||||
$this->dir = BASEDIR.'data/'.$dirname.'/';
|
||||
$this->projname = $projname;
|
||||
@@ -71,10 +73,23 @@ class CProject {
|
||||
$this->subtag = rtrim($matches[1], ' .');
|
||||
}
|
||||
|
||||
// Find `go-get` tags
|
||||
$this->longdesc = preg_replace_callback('~\[go-get\](.+)\[/go-get\]~', function($matches) {
|
||||
$this->go_get_target = $matches[1];
|
||||
return '';
|
||||
}, $this->longdesc);
|
||||
|
||||
// Find tags
|
||||
if (preg_match('~Tags: ([^\\n]+)~', $this->longdesc, $matches)) {
|
||||
$this->tags = array_map('trim', explode(',', $matches[1]));
|
||||
}
|
||||
|
||||
// Find `entry` tags
|
||||
$this->longdesc = preg_replace(
|
||||
'~\\[entry=([^\\]]+?)\\](.+?)\\[/entry\\]~m',
|
||||
'[url='.BASEURL.'\\1/]\\2[/url]', // hesc still hasn't happened, transform bbcode->bbcode
|
||||
$this->longdesc
|
||||
);
|
||||
|
||||
// Extract short description
|
||||
$parts = explode("\n", $this->longdesc);
|
||||
@@ -269,8 +284,20 @@ class CProject {
|
||||
|
||||
ob_start();
|
||||
$this->index();
|
||||
$idxfile = template($this->projname.' | '.SITE_TITLE, ob_get_clean());
|
||||
file_put_contents(BASEDIR.'wwwroot/'.$this->projname.'.html', $idxfile);
|
||||
|
||||
$extra_head_items = [];
|
||||
|
||||
$extra_head_items[] = '<link rel="canonical" href="'.hesc(BASEURL.$this->projname).'">'; // TODO include golang `go get` meta if necessary
|
||||
|
||||
if (strlen($this->go_get_target) > 0) {
|
||||
$extra_head_items[] = '<meta name="go-import" content="'.hesc($this->go_get_target).'">'; // TODO include golang `go get` meta if necessary
|
||||
}
|
||||
|
||||
$idxfile = template($this->projname.' | '.SITE_TITLE, ob_get_clean(), implode("\n", $extra_head_items));
|
||||
mkdir(BASEDIR.'wwwroot/'.$this->projname);
|
||||
|
||||
file_put_contents(BASEDIR.'wwwroot/'.$this->projname.'/index.html', $idxfile); // new URL format
|
||||
file_put_contents(BASEDIR.'wwwroot/'.$this->projname.'.html', redirecthtml(BASEURL.$this->projname)); // old URL format
|
||||
}
|
||||
|
||||
public function getClassAttr() {
|
||||
@@ -294,7 +321,7 @@ class CProject {
|
||||
<ul class="<?=$include_header ? 'downloads-large' : 'downloads-small' ?>">
|
||||
<?php foreach($render_downloads as $idx => $filename) { ?>
|
||||
<li>
|
||||
<a href="srv/<?=hesc($this->downloads_hashes[$idx])?>/<?=hesc(rawurlencode($filename))?>"><?=hesc($filename)?></a>
|
||||
<a href="<?=BASEURL?>srv/<?=hesc($this->downloads_hashes[$idx])?>/<?=hesc(rawurlencode($filename))?>"><?=hesc($filename)?></a>
|
||||
<small>
|
||||
<?=hesc(fbytes(filesize(BASEDIR.'wwwroot/srv/'.$this->downloads_hashes[$idx].'/'.$filename)))?>
|
||||
</small>
|
||||
@@ -338,7 +365,7 @@ class CProject {
|
||||
<?php if (count($this->images)) { ?>
|
||||
<div class="projimg">
|
||||
<?php foreach($this->images as $idx => $origname) { ?>
|
||||
<a href="img/<?=hesc(urlencode($this->projname))?>_<?=$idx?>.<?=str_ext($origname)?>"><img src="img/<?=hesc(urlencode($this->projname))?>_<?=$idx?>_thumb.jpg" class="thumbimage"></a>
|
||||
<a href="<?=BASEURL?>img/<?=hesc(urlencode($this->projname))?>_<?=$idx?>.<?=str_ext($origname)?>"><img src="<?=BASEURL?>img/<?=hesc(urlencode($this->projname))?>_<?=$idx?>_thumb.jpg" class="thumbimage"></a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
|
||||
1
lib/bootstrap.php
Normal file → Executable file
1
lib/bootstrap.php
Normal file → Executable file
@@ -29,6 +29,7 @@ function main($args) {
|
||||
}
|
||||
|
||||
define('BASEDIR', $basedir);
|
||||
define('BASEURL', trim($config['codesite']['baseurl']));
|
||||
define('SITE_TITLE', trim($config['codesite']['title']));
|
||||
define('PAGE_THUMB_W', intval($config['codesite']['page_thumb_w']));
|
||||
define('PAGE_THUMB_H', intval($config['codesite']['page_thumb_h']));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
function template($title, $content) {
|
||||
function template($title, $content, $extra_head='') {
|
||||
ob_start();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
@@ -9,9 +9,10 @@ function template($title, $content) {
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
|
||||
<meta name="viewport" content="width=960" >
|
||||
<link type="text/css" rel="stylesheet" href="static/normalize.css">
|
||||
<link type="text/css" rel="stylesheet" href="static/style.css">
|
||||
<script type="text/javascript" src="static/site.js"></script>
|
||||
<?=$extra_head?>
|
||||
<link type="text/css" rel="stylesheet" href="<?=BASEURL?>static/normalize.css">
|
||||
<link type="text/css" rel="stylesheet" href="<?=BASEURL?>static/style.css">
|
||||
<script type="text/javascript" src="<?=BASEURL?>static/site.js"></script>
|
||||
<title><?=hesc($title)?></title>
|
||||
</head>
|
||||
<body>
|
||||
@@ -108,6 +109,10 @@ function buildcommon() {
|
||||
array_map('imagedestroy', $handles); // free
|
||||
}
|
||||
|
||||
// Cache-busting stylesheet
|
||||
|
||||
$style = '.homeimage-sprite { background-image: url("logos.jpg?'.md5_file(BASEDIR.'wwwroot/logos.jpg').'"); }';
|
||||
|
||||
// Build index page
|
||||
|
||||
ob_start();
|
||||
@@ -119,6 +124,10 @@ function buildcommon() {
|
||||
<!-- }} -->
|
||||
<?php } ?>
|
||||
|
||||
<style type="text/css">
|
||||
<?php echo $style; ?>
|
||||
</style>
|
||||
|
||||
<table id="projtable-main" class="projtable">
|
||||
<?php foreach ($plist as $i => $pr) { ?>
|
||||
<tr class="<?=$pr->getClassAttr()?>"
|
||||
@@ -130,13 +139,13 @@ function buildcommon() {
|
||||
data-sort-ls="-<?=$pr->lifespan?>"
|
||||
>
|
||||
<td>
|
||||
<a href="<?=hesc(urlencode($pr->projname))?>.html"><?=(is_null($handle_lookup[$pr->projname]) ? '<div class="no-image"></div>' : '<div class="homeimage homeimage-sprite" style="background-position:0 -'.($handle_lookup[$pr->projname]*INDEX_THUMB_H).'px"></div>')?></a>
|
||||
<a href="<?=hesc(BASEURL.urlencode($pr->projname))?>/"><?=(is_null($handle_lookup[$pr->projname]) ? '<div class="no-image"></div>' : '<div class="homeimage homeimage-sprite" style="background-position:0 -'.($handle_lookup[$pr->projname]*INDEX_THUMB_H).'px"></div>')?></a>
|
||||
</td>
|
||||
<td>
|
||||
<strong><?=hesc(str_replace('_', ' ', $pr->projname))?></strong><?php if (SHOW_BLURBS) { ?>,
|
||||
<?=hesc($pr->shortdesc)?>
|
||||
<?php } ?>
|
||||
<a href="<?=hesc(urlencode($pr->projname))?>.html" class="article-read-more">more...</a>
|
||||
<a href="<?=hesc(BASEURL.urlencode($pr->projname))?>/" class="article-read-more">more...</a>
|
||||
<?php if (strlen($pr->subtag) || count($pr->tags)) { ?>
|
||||
<br>
|
||||
<small>
|
||||
@@ -155,20 +164,26 @@ function buildcommon() {
|
||||
</table>
|
||||
<?php
|
||||
|
||||
$index = template(SITE_TITLE, ob_get_clean());
|
||||
$extra_head = '<link rel="canonical" href="'.hesc(BASEURL).'">';
|
||||
|
||||
$index = template(SITE_TITLE, ob_get_clean(), $extra_head);
|
||||
file_put_contents(BASEDIR.'wwwroot/index.html', $index);
|
||||
|
||||
// Done
|
||||
}
|
||||
|
||||
function redirecthtml($target) {
|
||||
ob_start();
|
||||
?>
|
||||
<meta http-equiv="refresh" content="0; url=<?=hesc($target)?>">
|
||||
<a href="<?=hesc($target)?>">Moved »</a>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
function buildredirects($redirects) {
|
||||
foreach($redirects as $oldname => $newname) {
|
||||
ob_start();
|
||||
?>
|
||||
<meta http-equiv="refresh" content="0; url=<?=hesc($newname)?>.html">
|
||||
<a href="<?=hesc($newname)?>.html">Moved »</a>
|
||||
<?php
|
||||
$page = ob_get_clean();
|
||||
$page = redirecthtml($newname.'.html');
|
||||
file_put_contents(BASEDIR.'wwwroot/'.$oldname.'.html', $page);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,11 +133,11 @@ function text2html($sz) {
|
||||
$base = hesc($sz);
|
||||
|
||||
$base = preg_replace('~^=+(.+)=+~m', '<strong>\\1</strong>', $base);
|
||||
$base = preg_replace('~(https?://[^ \\r\\n\\t]+)~i', '<a href="\\1">\\1</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('~\\[b\\](.+?)\\[/b\\]~m', '<strong>\\1</strong>', $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('~\\[entry=([^\\]]+?)\\](.+?)\\[/entry\\]~m', '<a href="\\1.html">\\2</a>', $base);
|
||||
$base = preg_replace('~\n- ~ms', "\n• ", $base);
|
||||
|
||||
$btparts = explode('`', $base);
|
||||
|
||||
7
mkdist.sh
Normal file → Executable file
7
mkdist.sh
Normal file → Executable file
@@ -3,7 +3,12 @@
|
||||
set -eu
|
||||
|
||||
tar cJvf "codesite-$(date +%s).tar.xz" \
|
||||
rebuild.php rebuild.sh sites/codesite.example.com static_global \
|
||||
--exclude='sites/codesite.example.com/wwwroot' \
|
||||
rebuild.sh \
|
||||
sites/codesite.example.com \
|
||||
static \
|
||||
lib \
|
||||
--owner=0 --group=0
|
||||
|
||||
read -p "Press any key to continue..."
|
||||
|
||||
|
||||
0
rebuild.sh
Normal file → Executable file
0
rebuild.sh
Normal file → Executable file
Reference in New Issue
Block a user