diff --git a/main.go b/main.go
index 3c5437d..7922ad8 100644
--- a/main.go
+++ b/main.go
@@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"regexp"
+ "sort"
"strings"
"github.com/BurntSushi/toml"
@@ -88,11 +89,32 @@ func (this *Application) Homepage(w http.ResponseWriter, r *http.Request) {
}
}
+ // Sort repos once alphabetically, to get alphabetical indexes...
+ sort.Slice(repos, func(i, j int) bool {
+ return repos[i].Name < repos[j].Name
+ })
+ alphabeticalOrderIndexes := make(map[string]int, len(repos))
+ for idx, repo := range repos {
+ alphabeticalOrderIndexes[repo.Name] = idx
+ }
+
+ // But then make sure the final sort is by most-recently-created
+ sort.Slice(repos, func(i, j int) bool {
+ return repos[i].CreatedAt.After(repos[j].CreatedAt)
+ })
+
// Ready for template
this.Templatepage(w, r, "", "", func() {
fmt.Fprint(w, `
- `+this.cfg.Template.HomepageHeaderHTML+`
+ `+this.cfg.Template.HomepageHeaderHTML+`
+
+
Projects
`)
@@ -120,7 +142,13 @@ func (this *Application) Homepage(w http.ResponseWriter, r *http.Request) {
}
fmt.Fprint(w, `
-
+
|
diff --git a/static/site.js b/static/site.js
index 8864376..09d2d98 100644
--- a/static/site.js
+++ b/static/site.js
@@ -52,7 +52,7 @@
});
//
- // Sort support (theme opt-in)
+ // Sort support
//
var sort_rows = function(cb) {
@@ -62,7 +62,7 @@
items.push([i, cb(tr[i])]);
}
items.sort(function(a, b) {
- return (a[1] - b[1]);
+ return (b[1] - a[1]);
});
for (var i = 0, e = items.length; i !== e; ++i) {
var el = tr[items[i][0]];
@@ -72,12 +72,20 @@
}
};
- var sort_update = function(sort_by) {
+ var sortUpdate = function(sort_by) {
sort_rows(function(el) {
return el.getAttribute(sort_by);
});
};
- window.sortUpdate = sort_update;
+ var so = document.getElementById('sortorder');
+ if (so) {
+ so.addEventListener('change', function() { sortUpdate(so.value); });
+ sortUpdate(so.value);
+ }
+ window.addEventListener("load", function() {
+ // back button support in webkit
+ sortUpdate(so.value);
+ });
})();