From 0f70fc7bf0e693d516c8b223980403f308e16087 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 5 Apr 2015 16:22:46 +1200 Subject: [PATCH] support sorting --- rebuild.php | 35 ++++++++++-- sites/code.ivysaur.me/homepage_blurb.htm | 6 ++ sites/codesite.example.com/homepage_blurb.htm | 8 ++- static_global/site.js | 55 ++++++++++++++++++- 4 files changed, 97 insertions(+), 7 deletions(-) diff --git a/rebuild.php b/rebuild.php index 60976c9..be4d1d6 100644 --- a/rebuild.php +++ b/rebuild.php @@ -151,6 +151,7 @@ class CProject { public $projname; public $shortdesc = '(no description)'; public $subtag = ''; + public $lastupdate = 0; private $longdesc = ''; private $images = array(); private $downloads = array(); @@ -169,6 +170,8 @@ class CProject { if ($file[0] == '.') continue; if ($file == 'README.txt') { + $this->lastupdate = max($this->lastupdate, filectime($this->dir.$file)); // don't count README updates + $this->longdesc = file_get_contents($this->dir.'README.txt'); $matches = array(); if (preg_match('~Written in ([^\\r\\n]+)~', $this->longdesc, $matches)) { @@ -184,7 +187,13 @@ class CProject { $this->shortdesc[0] = strtolower($this->shortdesc[0]); // cosmetic lowercase continue; } - + + $this->lastupdate = max( + $this->lastupdate, + filemtime($this->dir.$file), + filectime($this->dir.$file) + ); + if (is_image($file)) { $this->images[] = $file; } else { @@ -360,6 +369,8 @@ function buildcommon() { $handles = array(); $handle_lookup = array(); + $alphasort = []; + foreach($projects as $dirname => $projectname) { $pr = new CProject($dirname, $projectname); @@ -373,6 +384,18 @@ function buildcommon() { $handle_lookup[$projectname] = count($handles); $handles[] = $pr->homeimage; } + + $alphasort[] = [$pr->projname, count($plist)-1]; + } + + usort($alphasort, function($a, $b) { + return strcasecmp($a[0], $b[0]); + }); + + $alphaidx = []; + + foreach($alphasort as $a) { + $alphaidx[ $a[1] ] = count($alphaidx); } // Build homepage spritesheet @@ -391,9 +414,13 @@ function buildcommon() { - - - +
+ $pr) { ?> + diff --git a/sites/code.ivysaur.me/homepage_blurb.htm b/sites/code.ivysaur.me/homepage_blurb.htm index 1f6a0de..1176be2 100644 --- a/sites/code.ivysaur.me/homepage_blurb.htm +++ b/sites/code.ivysaur.me/homepage_blurb.htm @@ -16,5 +16,11 @@

+ + PROJECTS

diff --git a/sites/codesite.example.com/homepage_blurb.htm b/sites/codesite.example.com/homepage_blurb.htm index de07484..c629971 100644 --- a/sites/codesite.example.com/homepage_blurb.htm +++ b/sites/codesite.example.com/homepage_blurb.htm @@ -4,5 +4,11 @@

+ + PROJECTS -

\ No newline at end of file +

diff --git a/static_global/site.js b/static_global/site.js index b65a989..5cfa896 100644 --- a/static_global/site.js +++ b/static_global/site.js @@ -33,14 +33,65 @@ }; var get_show_tag = function(tag) { - return function() { show_tag(tag); return false; }; + return function() { + show_tag(tag); + return false; + }; }; + var sort_rows = function(cb) { + var tr = document.querySelectorAll(".projtable tr"); + var items = []; + for (var i = 0, e = tr.length; i !== e; ++i) { + items.push([i, cb(tr[i])]); + } + items.sort(function(a, b) { + return (a[1] - b[1]); + }); + for (var i = 0, e = items.length; i !== e; ++i) { + var el = tr[items[i][0]]; + var parent = el.parentElement; + parent.removeChild(el); + parent.appendChild(el); + } + }; + + var sort_update = function() { + var cb; + switch(document.getElementById('sortorder').value) { + case 'a': + default: { + cb = function(el) { + return el.getAttribute('data-sort-ct'); + }; + } break; + + case 'b': { + cb = function(el) { + return el.getAttribute('data-sort-mt'); + } + } break; + + case 'c': { + cb = function(el) { + return el.getAttribute('data-sort-al'); + } + } break; + }; + sort_rows(cb); + }; + window.addEventListener('load', function() { var taglinks = document.querySelectorAll(".tag-link"); for (var i = 0, e = taglinks.length; i !== e; ++i) { var tag = taglinks[i].getAttribute("data-tag"); taglinks[i].addEventListener('click', get_show_tag(tag)); } + + var so = document.getElementById('sortorder'); + if (so) { + so.addEventListener('change', sort_update); + sort_update(); + } }); -})(); \ No newline at end of file +})();
projname]) ? '
' : '
')?>