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 news.md from index.html,
because we want to delay processing of index.html until news.md 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 Common-Lisp.net! title: Welcome to Common-Lisp.net!
depends-on:
- news.md
--- ---
<main id="bodyText"> <main id="bodyText">
<a class="btn btn-primary float-right" href="/downloads"><i class="fa fa-arrow-right"></i>&nbsp;&nbsp;Get started</a> <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 -*- ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(in-package :cl-site) (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) (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*) (ensure-directories-exist *OUTPUT-DIR*)
(format t "Generating site in ~A.~%" *output-dir*) (format t "Generating site in ~A.~%" *output-dir*)
(process-static *static-dir* *output-dir*) (process-static *static-dir* *output-dir*)
(process-static (merge-pathnames #P"static/" *layout-dir*) *output-dir*) (process-static (merge-pathnames #P"static/" *layout-dir*) *output-dir*)
(generate-news) (generate-news)
(dolist (page (populate-pages)) (loop for page in pages
(let ((page-path (make-path *pages-dir* page t))) for page-path = (make-path *pages-dir* page t)
(multiple-value-bind for rel-page-path = (enough-namestring page-path *pages-dir*)
(header content) for page-lines = (with-open-file (f page-path :direction :input)
(split-content-from-header page-path) (loop for line = (read-line f nil)
(let* ((header-text (format nil "~{~A~%~}" header)) while line
(parsed-header (when header (yaml:parse header-text))) collect line))
(page-context for header = (yaml:parse (format nil "~{~A~%~}" (header-lines page-lines)))
(append page for content = (format nil "~{~A~%~}" (content-lines page-lines))
(when parsed-header for context = (append page
(loop for k being each hash-key of parsed-header (when header
using (hash-value v) (loop for k being each hash-key of header
collect (cons k v)))))) using (hash-value v)
(preprocess-md-page (format nil "~{~A~%~}" content) page-context collect (cons k v))))
(list #'preprocess-lisp-page for dependencies = (cdr (assoc "depends-on" context :test #'string=))
(lambda (page context next-processors) for satisfies-deps-fn = (let ((deps dependencies))
(process-page page context)))))))))) (lambda ()
(every (lambda (d) (member d processed-pages :test #'string=))
deps)))
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
and
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*)) (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