Changeset 18125 in project


Ignore:
Timestamp:
05/21/10 20:08:52 (9 years ago)
Author:
Moritz Heidkamp
Message:

load all pages' page-vars before actually compiling them in order to allow creating navigational and pagination links

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/hyde/hyde.scm

    r18121 r18125  
    3535(define default-extension (make-parameter "html"))
    3636(define default-page-vars (make-parameter '()))
    37 (define page-eval-env (make-parameter (environment-copy (interaction-environment))))
     37
    3838(define translators (make-parameter '()))
    3939(define page-vars (make-parameter '()))
    40 
     40(define pages (make-parameter '()))
     41(define page-eval-env (make-parameter (environment-copy (interaction-environment))))
    4142(environment-set! (page-eval-env) '$ (lambda (name)
    4243                                       (alist-ref name (page-vars))))
     
    6768              (page-vars (append meta (page-vars)))
    6869              (environment-set! (page-eval-env) 'contents contents)
     70              (environment-set! (page-eval-env) 'pages (pages))
    6971              (translator))
    7072            (error (format "unknown layout format: ~A" layout)))))))
     
    110112      (with-output-to-string translate))))
    111113
     114(define (load-page-vars file)
     115  (parameterize
     116   (pages (cons (list (pathname-relative-from (source-dir) file)
     117                      (pathname-relative-from (output-dir) (make-output-path file))
     118                      (with-input-from-file file read)) (pages)))))
     119
    112120(define (compile-page source-file)
    113121  (display "* ")
     
    115123  (let ((target-file (compile-by-extension source-file)))
    116124    (print " -> " (pathname-relative-from (output-dir) target-file))))
     125
     126(define (exclude-file? file)
     127  (not (any (cut irregex-search <> file) (excluded-paths))))
    117128
    118129(define (compile-pages)
     
    122133    (create-directory (output-dir)))
    123134
    124   (print "compiling pages")
    125   (find-files (source-dir)
    126               (lambda (file) (not (any (cut irregex-search <> file) (excluded-paths))))
    127               (lambda (path _)
    128                 (if (directory? path)
    129                     (create-directory (make-output-path path))
    130                     (compile-page path)))))
     135  (parameterize ((pages '()))
     136    (print "preparing compilation")
     137    (find-files (source-dir)
     138                exclude-file?
     139                (lambda (path _)
     140                  (unless (directory? path)
     141                    (load-page-vars path))))
     142
     143    (print "compiling pages")
     144    (find-files (source-dir)
     145                exclude-file?
     146                (lambda (path _)
     147                  (if (directory? path)
     148                      (create-directory (make-output-path path))
     149                      (compile-page path))))))
    131150
    132151(define (read-sexps)
Note: See TracChangeset for help on using the changeset viewer.