Commits

Anonymous committed 4c7f497

Page part rendering

Comments (0)

Files changed (2)

 (import chicken scheme)
-(use files posix extras)
+(use files posix extras matchable sxml-transforms lowdown)
+
 
 (define pages
   (make-parameter '()))
 
 (define page-readers
   (make-parameter
-   '(("md" . ,read-markdown-page))))
+   `(("md" . ,markdown->sxml))))
 
 (define-record page
   type ; a symbol denoting this file's type (static, dynamic or directory)
                     (page-attr page extension:)))))
 
 
+(define (part name)
+  (lambda (page)
+    (list
+     (cons (make-page-path page name)
+           (read-page-part page name)))))
+
+(define (read-page-part* reader file)
+  (with-input-from-file file reader))
+
 ;; Reads a page part, 'content by default, and returns its SXML
 ;; representation. There will be a parameter (page-readers) or
 ;; something which is an alist of file extensions to reader
 ;; procedures. Those are checked in order for presence and the first
 ;; matching one is used.
-(define (read-page page #!optional (part 'content))
-  page)
+(define (read-page-part page #!optional (part 'content))
+  (let ((part (make-pathname "" (symbol->string part) "part"))
+        (dir  (pathname-directory (page-source-path page))))
+    (let loop ((readers (page-readers)))
+      (if (null? readers)
+          (error "Couldn't find page part" page part)
+          (let ((file (make-pathname dir part (caar readers))))
+            (if (file-exists? file)
+                (read-page-part* (cdar readers) file)
+                (loop (cdr readers))))))))
 
 ;; The default page rendering function. A page rendering function must
 ;; return a list of pairs with the car being the target path and the
 ;; renders the page's `content` part and wraps it in the `default`
 ;; layout and uses the current `make-page-path` function to generate
 ;; its name.
-#;
-(define (render-page page #!key title extension path)
-  (list (cons ((make-page-path) page 'content)
-              (default-layout (read-page page 'content)))))
+(define default-content-renderer
+  ;;(with-template (part 'content 'index) 'default)
+  (part 'content))
+
+;; (with-template (part 'content) 'default) => 
+;; (lambda (page . attrs)
+;;   (apply read-template
+;;          'default
+;;          page: page
+;;          content: ((part 'content) page)
+;;          attrs))
+
+(define (render-page page)
+  (append-map (lambda (render)
+                (render page))
+              (page-attr page render:)))
+
+
 
+(define (serialize-sxml sxml)
+  (SRV:send-reply (pre-post-order* sxml universal-conversion-rules*)))
 
 (define (compile-page page dest)
   (let ((page-dest-path (make-pathname dest (page-path page))))
       ((static)
        (print "copying " (page-path page) " to " page-dest-path)
        (file-copy (page-source-path page) page-dest-path #t))
+      ((dynamic)
+       (print "compiling dynamic page " page)
+       (for-each (match-lambda
+                  ((dest-path . content)
+                   (create-directory (pathname-directory dest-path) #t)
+                   (with-output-to-file dest-path
+                     (lambda ()
+                       (serialize-sxml content)))))
+                 (render-page page)))
       (else (fprintf (current-error-port)
                      "skipping page of unknown type: ~S~%"
                      page)))))

ideas/page-dir/src/a-nice-page/page.scm

   ;; this is the default
   ;;  render: (list (with-template (part 'content 'index) 'default))
   )
-
-;; (define (part name)
-;;   (lambda (page)
-;;     (read-part page name)))
-
-;; (with-template (part 'content) 'default) => 
-;; (lambda (page . attrs)
-;;   (apply read-template
-;;          'default
-;;          page: page
-;;          content: ((part 'content) page)
-;;          attrs))