www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

indexes.rkt (1354B)


      1 #lang racket/base
      2 (require racket/string
      3          scribble/html
      4          plt-web)
      5 
      6 (provide generate-index-html)
      7 
      8 (define (generate-index-html dest-dir sub-dir www-site)
      9   (define content
     10     (for/list ([f (directory-list (build-path dest-dir sub-dir))])
     11       (define fp (build-path dest-dir sub-dir f))
     12       (if (file-exists? fp)
     13           (cons f (file-size fp))
     14           (cons f 'dir))))
     15   (cond
     16    [www-site
     17     (define web-dir (string-join (map path-element->string (explode-path sub-dir)) "/"))
     18     (log-error "web ~s" web-dir)
     19     (define s
     20       (site web-dir
     21             #:url "http://index.racket-lang.org"
     22             #:share-from www-site
     23             #:always-abs-url? #f))
     24     (define is (index-site s))
     25     (index-page is 'same content)
     26     (void)]
     27    [else
     28     (define page-content
     29       (html (head (title "Index"))
     30             (body (table
     31                    (for/list ([c (in-list content)])
     32                      (tr (td (a href: (car c)
     33                                 ((if (eq? 'dir (cdr c))
     34                                      (lambda (p)
     35                                        (format "[~a]" p))
     36                                      values)
     37                                  (car c))))))))))
     38     (call-with-output-file*
     39      (build-path dest-dir sub-dir "index.html")
     40      (lambda (o)
     41        (output-xml page-content o)))]))
     42