Commit a4b1ae75 authored by Erik Huelsmann's avatar Erik Huelsmann

Remove more globals

Note that this commit adds a metadata header section to each
file; this section can be used to define variable values which
will be consumed by the layout in which the content is being

This commit moves the page title definition to the content files,
instead of (hard) coding those as detached values in globals.lisp
parent 2e375786
title: | About
<h1><i class="far fa-question-circle"></i>&nbsp;About</h1>
<p> provides hosting for projects and user groups
title: Frequently asked questions
<h1><i class="far fa-question-circle"></i>&nbsp;FAQ - Frequently Asked Questions</h1>
title: GitLab migration
<main id="bodyText">
<header id="summary">
title: Migration to GitLab
<h2> migration to GitLab: status</h2>
title: Independent Mailing Lists
<div id="bodyText">
<h1>Independent Mailing Lists</h1>
<h2 id="apply">How to apply</h2>
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>
<h1>Welcome to</h1>
title: Orphaned mailing lists
<div id="bodyText">
<h2 id="intro">Introduction</h2>
title: Orphaned projects
<h1>Orphaned Projects</h1>
<div id="bodyText">
<h2 id="intro">Introduction</h2>
title: Projects
<a style="clear:both;" class="btn btn-primary float-right" href="/project-intro"><i class="fa fa-arrow-right"></i>&nbsp;&nbsp;Projects Hosting</a>
<div id="bodyText">
<h1 style="padding-bottom: 30px;"><i class="fa fa-project-diagram"></i>&nbsp; projects</h1>
title: Project Hosting
<a style="clear:both;" class="btn btn-primary float-right" href="/phub"><i class="fa fa-arrow-right"></i>&nbsp;&nbsp; projects</a>
<div style="clear:both;margin-top: 20px;" class="tocbox">
......@@ -23,37 +23,11 @@
"Pathname for location of page content.")
(defparameter *PRIVATE-KEYS* '(:slug :content))
;; Extra context for pages
(defparameter *PAGE-CONTEXT*
`(("about.html" ((:title . " | About")))
("index.html" ((:title . "Welcome to!")))
("faq.html" ((:title . "Frequently asked questions")))
("gitlab-migration-repository-mapping.html" ((:title . "GitLab migration")))
("gitlab-migration-status.html" ((:title . "Migration to GitLab")))
("independent-lists.html" ((:title . "Independent Mailing Lists")))
("orphaned-mailing-lists.html" ((:title . "Orphaned mailing lists")))
("orphaned-projects.html" ((:title . "Orphaned projects")))
("phub.html" ((:title . "Projects")))
("project-intro.html" ((:title . "Project Hosting")))))
(defun page-context (filename)
(cadr (assoc filename *page-context* :test 'equalp)))
(defun page-title (filename)
(or (cdr (assoc :title (page-context filename)))
(format nil " | ~a"
(pathname-name (pathname filename))))))
(defparameter *PAGES*
(mapcar (lambda (p)
(let ((context
(append (list (cons :content (file-namestring p)))
(page-context (file-namestring p)))))
(when (not (assoc :title context))
(push (cons :title (page-title (file-namestring p)))
(list (cons :content (file-namestring p))
(cons :title (file-namestring p))))
(directory (make-pathname :defaults *PAGES-DIR*
:name :wild
:type "html")))
;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(in-package :cl-site)
(defun split-content-from-header (path)
"Returns two values; the header and the content"
(with-open-file (f path :direction :input)
(let ((header-lines
(loop for line = (read-line f nil)
unless line do (return-from split-content-from-header
(values nil lines))
when (string= line "---") return lines
collect line into lines)))
(loop for line = (read-line f nil)
collect line into lines
unless line
return (values header-lines lines)))))
;; Copies/renders static assets (imgs, etc)
(defun process-static ()
(let ((destination-root (merge-pathnames #P"static/" *output-dir*))
......@@ -20,22 +35,24 @@
(defun render-page (page template-path)
((page-path (make-path *PAGES-DIR* page t))
(output-path (make-path *OUTPUT-DIR* page t))
(page-content (let ((mustache:*load-path* (cons *PAGES-DIR* mustache:*load-path*))
(mustache:*default-pathname-type* "html"))
(mustache:render* page-path)))
(page-context (remove-if (lambda (p) (find p *PRIVATE-KEYS*))
(push (cons :page-content page-content) page) :key 'car)))
(with-open-file (output-stream output-path
:direction :output
:if-exists :supersede)
(let ((mustache:*load-path* (cons *PAGES-DIR* mustache:*load-path*))
(mustache:*default-pathname-type* "html"))
(mustache:render template-path (append page-context *GLOBAL-CONTEXT*)
(let ((page-path (make-path *PAGES-DIR* page t))
(output-path (make-path *OUTPUT-DIR* page t)))
(header content)
(split-content-from-header page-path)
(let* ((header-text (format nil "~{~A~%~}" header))
(content-text (format nil "~{~A~%~}" content))
(parsed-header (yaml:parse header-text))
(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)
(mustache:render template-path (append (acons :page-content content-text page-context) *GLOBAL-CONTEXT*)
(defun process-pages (pages)
(format t "Processing pages..~%")
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