Commit 246f5da9 authored by Erik Huelsmann's avatar Erik Huelsmann

Retain the original filename for Markdown pages

Note that the Markdown preprocessor is now converted to an 'around method'-like
concept which passes content and context from one around processor to another.

Around processors may elect to pre- or post-process.
parent 4a6dee29
......@@ -10,8 +10,6 @@ output/
system-index.txt
content/newsbox.html
content/about.html
content/libraries.html
content/lisp-companies.html
content/news.html
*.dx64fsl
*.fasl
\ No newline at end of file
*.fasl
......@@ -8,16 +8,27 @@
(process-static *static-dir* *output-dir*)
(process-static (merge-pathnames #P"static/" *layout-dir*) *output-dir*)
(let ((pages (populate-pages)))
(format t "Preprocessing Markdown pages..~%")
(dolist (page pages)
(preprocess-md-page page))
(format t "Preprocessing LHTML pages..~%")
(dolist (page pages)
(preprocess-lisp-page page)))
(generate-news)
(dolist (page (populate-pages))
(process-page page))))
(let ((page-path (make-path *pages-dir* page t)))
(multiple-value-bind
(header content)
(split-content-from-header page-path)
(let* ((header-text (format nil "~{~A~%~}" header))
(parsed-header (when header (yaml:parse header-text)))
(page-context
(append page
(when parsed-header
(loop for k being each hash-key of parsed-header
using (hash-value v)
collect (cons k v))))))
(preprocess-md-page (format nil "~{~A~%~}" content) page-context
(list (lambda (page context next-processors)
(process-page page context))))))))))
(defun make-clean (&optional (output-dir *output-dir*))
......
......@@ -45,45 +45,29 @@
(with-output-to-string (output-stream)
(render-template template context output-stream)))
(defun render-page (page template-path)
(let ((page-path (make-path *PAGES-DIR* page t))
(output-path (make-path *OUTPUT-DIR* page t)))
(defun render-page (content context template-path)
(let ((output-path (make-pathname :defaults (make-path *OUTPUT-DIR* context t) :type "html")))
(ensure-directories-exist output-path)
(multiple-value-bind
(header content)
(split-content-from-header page-path)
(let* ((header-text (format nil "~{~A~%~}" header))
(content-text (format nil "~{~A~%~}" content))
(parsed-header (when header (yaml:parse header-text)))
(page-context
(when parsed-header
(loop for k being each hash-key of parsed-header
using (hash-value v)
collect (cons k v)))))
(with-open-file (output-stream output-path
:direction :output
:if-exists :supersede)
(render-template template-path
(append (acons :page-content (render-template* content-text)
(acons :rel-path (enough-namestring page-path *pages-dir*) page-context))
*GLOBAL-CONTEXT*)
output-stream))))))
(defun preprocess-md-page (page)
(let* ((md-file (make-path *pages-dir* page t)))
(when (string= (pathname-type md-file) "md")
(let ((html-file (make-pathname :defaults md-file :type "html")))
(format t "Transforming ~A to ~A~%" md-file html-file)
(multiple-value-bind
(header content)
(split-content-from-header md-file)
(let ((md-content (with-output-to-string (out) (cl-markdown:markdown (format nil "~{~A~%~}" content) :stream out))))
(with-open-file (f html-file
:direction :output
:if-exists :supersede)
(when header
(format f "~{~A~%~}---~%" header))
(format f "~A~%" md-content))))))))
(with-open-file (output-stream output-path
:direction :output
:if-exists :supersede)
(render-template template-path
(append (acons :page-content (render-template* content)
(acons :rel-path (enough-namestring (cdr (assoc :content context)) *pages-dir*)
context))
*GLOBAL-CONTEXT*)
output-stream))))
(defun preprocess-md-page (content context next-processors)
(let* ((md-file (make-path *pages-dir* context t)))
(unless (string= (pathname-type md-file) "md")
(return-from preprocess-md-page (funcall (pop next-processors) content context next-processors)))
(let ((html-file (make-pathname :defaults md-file :type "html")))
(format t "Transforming ~A to ~A~%" md-file html-file)
(let ((md-content (with-output-to-string
(out)
(cl-markdown:markdown content :stream out))))
(funcall (pop next-processors) md-content context next-processors)))))
(defun preprocess-lisp-page (page)
(let* ((lisp-file (page-content page)))
......@@ -101,12 +85,10 @@
(format out "---~%")
(write-string (getf *computed-page-content* :html-string) out)))))))
(defun process-page (page)
(let ((page-path (cdr (assoc :content page)))
(template-path (pathname (merge-pathnames *templates-dir* *DEFAULT-PAGE-TEMPLATE*))))
(when (string= (pathname-type page-path) "html")
(format t "Rendering ~A~%" page-path)
(render-page page template-path))))
(defun process-page (content context)
(let ((template-path (pathname (merge-pathnames *templates-dir* *DEFAULT-PAGE-TEMPLATE*))))
(format t "Rendering ~A~%" (cdr (assoc :content context)))
(render-page content context template-path)))
;; Process news
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment