8 Commits
v64 ... v72

6 changed files with 64 additions and 18 deletions

View File

@@ -1 +1,2 @@
42a17645b5b21d7fe395767de7fa3e26ee999014 release-r54
0f89ae041c2ee60cc1ea308d047fce816b19c490 release-r64

View File

@@ -1,16 +1,8 @@
- Support project redirection (e.g. `code.ivysaur.me` was renamed to `codesite`, breaking links)
- If no projects have any images, don't generate spritesheet
- Move tag javascript and no-image image out of per-site configuration
- Merge "written in" and "tags"
- Per-project directories, to prevent overwriting files (e.g. 'screenshot.jpg')
- Cache recent changes somehow
- RSS for recent changes
- RSS for all projects
- Switchable CSS (reddit theme, 4chan theme, HN theme)

View File

@@ -14,6 +14,12 @@ Written in PHP, Bash
=CHANGELOG=
2015-04-05: r72
- Feature: Support redirecting old project names
- Feature: Add file hash in download URLs to prevent filename collisions
- Fix an issue generating spritesheets even if no project images are present
- Don't include `ctime` when estimating project update time
2015-04-05: r64
- Feature: Support sorting projects

View File

@@ -155,6 +155,7 @@ class CProject {
private $longdesc = '';
private $images = array();
private $downloads = array();
private $downloads_hashes = array();
public $tags = array();
public $homeimage = null;
@@ -190,8 +191,8 @@ class CProject {
$this->lastupdate = max(
$this->lastupdate,
filemtime($this->dir.$file),
filectime($this->dir.$file)
// filectime($this->dir.$file),
filemtime($this->dir.$file)
);
if (is_image($file)) {
@@ -203,6 +204,12 @@ class CProject {
natcasesort($this->downloads);
$this->downloads = array_reverse($this->downloads);
for($i = 0, $e = count($this->downloads); $i !== $e; ++$i) {
$this->downloads_hashes[] = (
sha1_file($this->dir.$this->downloads[$i])
);
}
}
public function genHomeImage() {
@@ -231,7 +238,21 @@ class CProject {
// Copy downloads to wwwroot
foreach($this->downloads as $idx => $filename) {
copy($this->dir.$filename, BASEDIR.'wwwroot/srv/'.$filename);
$cmkdir = @mkdir( BASEDIR.'wwwroot/srv/'.$this->downloads_hashes[$idx] );
if (! $cmkdir) {
fputs(
STDOUT,
"WARNING: Couldn't create directory ".$this->downloads_hashes[$idx].
" for file '${filename}'".
" in project '".$this->projname."'!\n"
);
}
copy(
$this->dir.$filename,
BASEDIR.'wwwroot/srv/'.$this->downloads_hashes[$idx].'/'.$filename
);
}
// Generate index page
@@ -269,11 +290,11 @@ class CProject {
<strong>DOWNLOAD</strong>
<ul>
<?php foreach($this->downloads as $filename) { ?>
<?php foreach($this->downloads as $idx => $filename) { ?>
<li>
<a href="srv/<?=hesc(rawurlencode($filename))?>"><?=hesc($filename)?></a>
<a href="srv/<?=hesc($this->downloads_hashes[$idx])?>/<?=hesc(rawurlencode($filename))?>"><?=hesc($filename)?></a>
<small>
<?=hesc(fbytes(filesize(BASEDIR.'wwwroot/srv/'.$filename)))?>
<?=hesc(fbytes(filesize(BASEDIR.'wwwroot/srv/'.$this->downloads_hashes[$idx].'/'.$filename)))?>
</small>
</li>
<?php } ?>
@@ -400,8 +421,10 @@ function buildcommon() {
// Build homepage spritesheet
mkspritesheet($handles, BASEDIR.'wwwroot/logos.jpg', INDEX_THUMB_W, INDEX_THUMB_H);
array_map('imagedestroy', $handles); // free
if (count($handles)) {
mkspritesheet($handles, BASEDIR.'wwwroot/logos.jpg', INDEX_THUMB_W, INDEX_THUMB_H);
array_map('imagedestroy', $handles); // free
}
// Build index page
@@ -452,6 +475,18 @@ function buildcommon() {
// Done
}
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 &raquo;</a>
<?php
$page = ob_get_clean();
file_put_contents(BASEDIR.'wwwroot/'.$oldname.'.html', $page);
}
}
function main($args) {
$basedir = './';
$total = $args[0];
@@ -480,6 +515,9 @@ function main($args) {
if ($pos == 0) {
buildcommon();
if (array_key_exists('redirect', $config)) {
buildredirects( $config['redirect'] );
}
} else {
buildprojects($pos, array_decimate(listprojects(), $total, $pos));
}

View File

@@ -6,3 +6,7 @@ index_thumb_w=90
index_thumb_h=32
; n.b. Recommend a multiple of the JPEG iDCT block size for index_thumb_h
[redirect]
; old project name = new project name
code.ivysaur.me=codesite

View File

@@ -6,3 +6,8 @@ index_thumb_w=90
index_thumb_h=32
; n.b. Recommend a multiple of the JPEG iDCT block size for index_thumb_h
[redirect]
; old project name = new project name
old-project-name=example-project