diff --git a/collects/meta/web/download/data.rkt b/collects/meta/web/download/data.rkt index 9a7c910cac..c69b19c81c 100644 --- a/collects/meta/web/download/data.rkt +++ b/collects/meta/web/download/data.rkt @@ -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)] [name (let ([t (make-hasheq)]) diff --git a/collects/meta/web/download/download-pages.rkt b/collects/meta/web/download/download-pages.rkt index 5d8c8360c4..bfb1fe731f 100644 --- a/collects/meta/web/download/download-pages.rkt +++ b/collects/meta/web/download/download-pages.rkt @@ -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= 0) return i * 10; + for (var i=0@";" 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