Change the download order.

Done in two steps: first, make the list of installers have a good order
(determined by package, then OS type, then cpu, etc); make the JS code
that re-sorts the entries move only the desired options to the top but
otherwise use the original order (which is the previous thing).
This commit is contained in:
Eli Barzilay 2010-12-13 03:21:38 -05:00
parent db116cd14b
commit 3199fd166f
2 changed files with 51 additions and 33 deletions

View File

@ -82,9 +82,6 @@
["plt" "Racket Package"]
["sit" "StuffIt Archive"]))
;; Used to sort packages when more then one is rendered on a page
(define -package-order- '(racket racket-textual))
(define -mirrors-
;; This is a sequence of
;; (location url reposnisble-name email [techincal-contact])
@ -134,6 +131,15 @@
"solsona@acm.org"]
))
;; Used to sort packages when more then one is rendered on a page
(define (-installer-orders-)
`((,installer-package ,eq? (racket racket-textual))
(,installer-binary? ,eq? (#t #f))
(,installer-platform ,regexp-match?
(#px"\\bwin(32)?\\b" #px"\\bmac\\b" #px"\\blinux\\b" #px""))
(,installer-platform ,regexp-match?
(#px"\\bi386\\b" #px"\\bx86_64\\b" #px"\\bppc\\b" #px""))))
;; ----------------------------------------------------------------------------
(provide versions+dates all-versions current-version version->date
@ -221,19 +227,34 @@
(error 'installers "bad installer data line#~a: ~s"
num line))))))
;; sorted by version (newest first), and then by -package-order-
(define (order->precedes order)
(define =? (car order))
(define l (cadr order))
(define (num-of x)
(let loop ([l l] [n 0])
(cond [(null? l)
(error 'precedes "could not find ~s in precedence list: ~s" x l)]
[(=? (car l) x) n]
[else (loop (cdr l) (add1 n))])))
(lambda (x y) (< (num-of x) (num-of y))))
;; sorted by version (newest first), and then by -installer-orders-
(define all-installers
(sort (call-with-input-file installers-data parse-installers)
(lambda (i1 i2)
(let ([v1 (installer-version-number i1)]
[v2 (installer-version-number i2)])
(or (> v1 v2)
(and (= v1 v2)
(let* ([p1 (installer-package i1)]
[p2 (installer-package i2)]
[t1 (memq p1 -package-order-)])
(and t1 (or (memq p2 (cdr t1))
(not (memq p2 -package-order-)))))))))))
(sort
(call-with-input-file installers-data parse-installers)
(let ([fns `([,installer-version-number . ,>]
,@(map (lambda (o) (cons (car o) (order->precedes (cdr o))))
(-installer-orders-)))])
(lambda (i1 i2)
(let loop ([fns fns])
(if (null? fns)
#f
(let* ([get (caar fns)] [<? (cdar fns)] [x1 (get i1)] [x2 (get i2)])
(or (<? x1 x2) (and (equal? x1 x2) (loop (cdr fns)))))))))))
(with-output-to-file "/tmp/x" #:exists 'truncate
(lambda ()
(for ([i all-installers])
(printf "~s ~s\n" (installer-platform i) (installer-path i)))))
(define package->name
(let ([t (make-hasheq)])

View File

@ -92,6 +92,8 @@
location.href = selector[selector.selectedIndex].value;
}
// returns an ordering for the platform names, an array of regexps
// note that the entries are sorted in a good order, so return an order
// that only brings the locally desired entries to the top
function getPlatformOrder() {
var p = navigator.platform;
var l = function(str) { return p.indexOf(str) != -1@";" }
@ -104,18 +106,15 @@
Linux32 = /Linux.*i386/,
Unix = /Unix/,
Solaris = /Solaris/;
var default_order = [Win, Mac, Linux, Unix];
// The default is the common case
if (p == null) return default_order;
else if (l("SunOS")) return [Solaris, Unix, Linux, Mac, Win];
else if (l("Win")) return [Win, Mac, Linux, Unix];
else if (l("Mac"))
return [(l("Intel")?MacIntel:MacPPC), Mac, Unix, Linux, Win];
if (p == null) return [];
else if (l("SunOS")) return [Solaris, Unix];
else if (l("Win")) return [Win];
else if (l("Mac")) return [(l("Intel")?MacIntel:MacPPC), Mac, Unix];
else if (l("Linux")) {
// also show the linux explanation if it's a linux
document.getElementById("linux_explain").style.display = "block";
return [(l("_64")?Linux64:Linux32), Linux, Unix, Mac, Win];
} else return default_order;
return [(l("_64")?Linux64:Linux32), Linux, Unix];
} else return [];
}
// show the linux explanation on change too (do it with a timeout so it
// changes even when the arrow keys are used to move the selection -- since
@ -134,28 +133,26 @@
//
var opts = selector.options;
var len = opts.length;
var tmps = new Array(len); // temp array to sort the options
// get the order and a make a sorting function
var order = getPlatformOrder();
function getOrder(str) {
for (var i=0@";" i<len@";" i++)
if (str.search(order[i]) >= 0) return i * 10;
for (var i=0@";" i<order.length@";" i++)
if (str.search(order[i]) >= 0) return i;
return 999;
}
function isBetter(opt1,opt2) {
// sort first by the order, then by how they were placed originally
var ord1 = getOrder(opt1[0]), ord2 = getOrder(opt2[0]);
// prefer non-source
if (opt1[0].search("source")>=0) ord1 += 1;
if (opt2[0].search("source")>=0) ord2 += 1;
if (ord1 < ord2) return -1;
else if (ord1 > ord2) return +1;
else if (opt1[0] < opt2[0]) return -1;
else if (opt1[0] > opt2[0]) return +1;
else if (opt1[2] < opt2[2]) return -1;
else if (opt1[2] > opt2[2]) return +1;
else return 0;
}
// sort the options, need to use a temporary array
var tmps = new Array(len);
for (var i=0@";" i<len@";" i++)
tmps[i]=[opts[i].text,opts[i].value];
tmps[i]=[opts[i].text,opts[i].value,i];
tmps.sort(isBetter);
for (var i=0@";" i<len@";" i++) {
opts[i].text = tmps[i][0];