Commit 4a6dee29 authored by Erik Huelsmann's avatar Erik Huelsmann

Preprocess Markdown/LHTML pages one by one

This commit is one in a series which refactors
how pages are being generated in order to retain
the link between the original input document and
the HTML document ultimately being generated.
parent 7f2eedae
......@@ -8,8 +8,12 @@
(process-static *static-dir* *output-dir*)
(process-static (merge-pathnames #P"static/" *layout-dir*) *output-dir*)
(let ((pages (populate-pages)))
(preprocess-md-pages pages)
(preprocess-lisp-pages 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))
......
......@@ -69,41 +69,37 @@
*GLOBAL-CONTEXT*)
output-stream))))))
(defun preprocess-md-pages (pages)
(format t "Preprocessing Markdown pages..~%")
(dolist (page pages)
(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)))))))))
(defun preprocess-lisp-pages (pages)
(format t "Preprocessing LHTML pages..~%")
(dolist (page pages)
(let* ((lisp-file (page-content page)))
(when (string-equal (pathname-type lisp-file) "lisp")
(let ((html-file (make-pathname :defaults lisp-file :type "html")))
(format t "Loading ~a and creating fresh ~a...~%"
(file-namestring lisp-file) html-file)
(let (*computed-page-content*)
(load (merge-pathnames lisp-file *pages-dir*))
(with-open-file (out (merge-pathnames html-file *pages-dir*) :if-exists :supersede
:if-does-not-exist :create :direction :output)
(let ((headers (getf *computed-page-content* :headers)))
(mapc #'(lambda(key value) (format out "~a: ~a~%" key value))
(plist-keys headers)(plist-values headers)))
(format out "---~%")
(write-string (getf *computed-page-content* :html-string) out))))))))
(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))))))))
(defun preprocess-lisp-page (page)
(let* ((lisp-file (page-content page)))
(when (string-equal (pathname-type lisp-file) "lisp")
(let ((html-file (make-pathname :defaults lisp-file :type "html")))
(format t "Loading ~a and creating fresh ~a...~%"
(file-namestring lisp-file) html-file)
(let (*computed-page-content*)
(load (merge-pathnames lisp-file *pages-dir*))
(with-open-file (out (merge-pathnames html-file *pages-dir*) :if-exists :supersede
:if-does-not-exist :create :direction :output)
(let ((headers (getf *computed-page-content* :headers)))
(mapc #'(lambda(key value) (format out "~a: ~a~%" key value))
(plist-keys headers)(plist-values headers)))
(format out "---~%")
(write-string (getf *computed-page-content* :html-string) out)))))))
(defun process-page (page)
(let ((page-path (cdr (assoc :content page)))
......
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