Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 81c65b3cce | |||
| 441c05f096 | |||
| 671573bc2e | |||
| 17b0bea213 | |||
| 0ad96058d5 | |||
| 092efca34d | |||
| 0303019641 | |||
| 8efff11ac2 |
1
.hgtags
1
.hgtags
@@ -1 +1,2 @@
|
||||
42a17645b5b21d7fe395767de7fa3e26ee999014 release-r54
|
||||
0f89ae041c2ee60cc1ea308d047fce816b19c490 release-r64
|
||||
|
||||
12
TODO.txt
12
TODO.txt
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
50
rebuild.php
50
rebuild.php
@@ -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
|
||||
|
||||
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 »</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));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user