Commit ae09ef38 authored by Erik Huelsmann's avatar Erik Huelsmann

Introduce option to declare dependencies between content files

Note that we need to be able to declare a dependency on from index.html,
because we want to delay processing of index.html until has been processed
as we no longer want to process news twice.
This commit is a step towards moving the generation of 'newsbox.html' into a
post-processing step.
parent 53fa46ef
title: Welcome to!
<main id="bodyText">
<a class="btn btn-primary float-right" href="/downloads"><i class="fa fa-arrow-right"></i>&nbsp;&nbsp;Get started</a>
;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(in-package :cl-site)
(defun header-lines (lines)
(loop for line in lines
thereis (when (string= line "---") header-lines)
collect line into header-lines))
(defun content-lines (lines)
(loop with found-header-p = nil
for line in lines
when (string= line "---")
do (setf found-header-p t
content-lines nil)
collect line into content-lines
finally (return content-lines)))
(defun make-site (&optional output-dir)
(let ((*output-dir* (or output-dir *output-dir*)))
(let ((*output-dir* (or output-dir *output-dir*))
(pages (populate-pages)))
(ensure-directories-exist *OUTPUT-DIR*)
(format t "Generating site in ~A.~%" *output-dir*)
(process-static *static-dir* *output-dir*)
(process-static (merge-pathnames #P"static/" *layout-dir*) *output-dir*)
(dolist (page (populate-pages))
(let ((page-path (make-path *pages-dir* page t)))
(header content)
(split-content-from-header page-path)
(let* ((header-text (format nil "~{~A~%~}" header))
(parsed-header (when header (yaml:parse header-text)))
(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 #'preprocess-lisp-page
(lambda (page context next-processors)
(process-page page context))))))))))
(loop for page in pages
for page-path = (make-path *pages-dir* page t)
for rel-page-path = (enough-namestring page-path *pages-dir*)
for page-lines = (with-open-file (f page-path :direction :input)
(loop for line = (read-line f nil)
while line
collect line))
for header = (yaml:parse (format nil "~{~A~%~}" (header-lines page-lines)))
for content = (format nil "~{~A~%~}" (content-lines page-lines))
for context = (append page
(when header
(loop for k being each hash-key of header
using (hash-value v)
collect (cons k v))))
for dependencies = (cdr (assoc "depends-on" context :test #'string=))
for satisfies-deps-fn = (let ((deps dependencies))
(lambda ()
(every (lambda (d) (member d processed-pages :test #'string=))
for satisfies-deps-p = (funcall satisfies-deps-fn)
unless satisfies-deps-p
collect (list satisfies-deps-fn content context rel-page-path) into delayed-pages
do (format t "Delayed ~a~%" rel-page-path)
when satisfies-deps-p
do (preprocess-md-page content context
(list #'preprocess-lisp-page
(lambda (p c next-processors)
(process-page p c))))
collect rel-page-path into processed-pages
do (loop for resolved-deps-pages =
(loop for delay in delayed-pages
for satisfies-deps-p = (funcall (car delay))
when satisfies-deps-p
collect delay
and do (progn
(format t "Rendering delayed ~a~%" (fourth delay))
(push (fourth delay) processed-pages)
(preprocess-md-page (second delay) (third delay)
(list #'preprocess-lisp-page
(lambda (p c next-processors)
(process-page p c))))))
while resolved-deps-pages
do (setf delayed-pages
(set-difference delayed-pages resolved-deps-pages :key #'fourth :test #'string=))))))
(defun make-clean (&optional (output-dir *output-dir*))
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