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
included.

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: Common-Lisp.net | About
---
<h1><i class="far fa-question-circle"></i>&nbsp;About Common-Lisp.net</h1> <h1><i class="far fa-question-circle"></i>&nbsp;About Common-Lisp.net</h1>
<p> Common-Lisp.net provides hosting for projects and user groups <p> Common-Lisp.net provides hosting for projects and user groups
......
title: Frequently asked questions
---
<main> <main>
<article> <article>
<h1><i class="far fa-question-circle"></i>&nbsp;FAQ - Common-Lisp.net Frequently Asked Questions</h1> <h1><i class="far fa-question-circle"></i>&nbsp;FAQ - Common-Lisp.net Frequently Asked Questions</h1>
......
title: GitLab migration
---
<main id="bodyText"> <main id="bodyText">
<header id="summary"> <header id="summary">
<h2>Introduction</h2> <h2>Introduction</h2>
......
title: Migration to GitLab
---
<main> <main>
<article> <article>
<h2>Common-Lisp.net migration to GitLab: status</h2> <h2>Common-Lisp.net migration to GitLab: status</h2>
......
title: Independent Mailing Lists
---
<div id="bodyText"> <div id="bodyText">
<h1>Independent Mailing Lists</h1> <h1>Independent Mailing Lists</h1>
<h2 id="apply">How to apply</h2> <h2 id="apply">How to apply</h2>
......
title: Welcome to Common-Lisp.net!
---
<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>
<h1>Welcome to Common-Lisp.net</h1> <h1>Welcome to Common-Lisp.net</h1>
......
title: Orphaned mailing lists
---
<div id="bodyText"> <div id="bodyText">
<h2 id="intro">Introduction</h2> <h2 id="intro">Introduction</h2>
......
title: Orphaned projects
---
<h1>Orphaned Projects</h1> <h1>Orphaned Projects</h1>
<div id="bodyText"> <div id="bodyText">
<h2 id="intro">Introduction</h2> <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> <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"> <div id="bodyText">
<h1 style="padding-bottom: 30px;"><i class="fa fa-project-diagram"></i>&nbsp;Common-Lisp.net projects</h1> <h1 style="padding-bottom: 30px;"><i class="fa fa-project-diagram"></i>&nbsp;Common-Lisp.net 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;Common-Lisp.net projects</a> <a style="clear:both;" class="btn btn-primary float-right" href="/phub"><i class="fa fa-arrow-right"></i>&nbsp;&nbsp;Common-Lisp.net projects</a>
<div style="clear:both;margin-top: 20px;" class="tocbox"> <div style="clear:both;margin-top: 20px;" class="tocbox">
......
...@@ -23,37 +23,11 @@ ...@@ -23,37 +23,11 @@
"Pathname for location of page content.") "Pathname for location of page content.")
(defparameter *PRIVATE-KEYS* '(:slug :content)) (defparameter *PRIVATE-KEYS* '(:slug :content))
;; Extra context for pages
(defparameter *PAGE-CONTEXT*
`(("about.html" ((:title . "Common-Lisp.net | About")))
("index.html" ((:title . "Welcome to Common-Lisp.net!")))
("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 "Common-Lisp.net | ~a"
(string-capitalize
(pathname-name (pathname filename))))))
(defparameter *PAGES* (defparameter *PAGES*
(mapcar (lambda (p) (mapcar (lambda (p)
(let ((context (list (cons :content (file-namestring p))
(append (list (cons :content (file-namestring p))) (cons :title (file-namestring p))))
(page-context (file-namestring p)))))
(when (not (assoc :title context))
(push (cons :title (page-title (file-namestring p)))
context))
context))
(directory (make-pathname :defaults *PAGES-DIR* (directory (make-pathname :defaults *PAGES-DIR*
:name :wild :name :wild
:type "html"))) :type "html")))
......
;;;; -*- 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 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) ;; Copies/renders static assets (imgs, etc)
(defun process-static () (defun process-static ()
(let ((destination-root (merge-pathnames #P"static/" *output-dir*)) (let ((destination-root (merge-pathnames #P"static/" *output-dir*))
...@@ -20,22 +35,24 @@ ...@@ -20,22 +35,24 @@
(defun render-page (page template-path) (defun render-page (page template-path)
(let* (let ((page-path (make-path *PAGES-DIR* page t))
((page-path (make-path *PAGES-DIR* page t)) (output-path (make-path *OUTPUT-DIR* page t)))
(output-path (make-path *OUTPUT-DIR* page t)) (multiple-value-bind
(page-content (let ((mustache:*load-path* (cons *PAGES-DIR* mustache:*load-path*)) (header content)
(mustache:*default-pathname-type* "html")) (split-content-from-header page-path)
(mustache:render* page-path))) (let* ((header-text (format nil "~{~A~%~}" header))
(page-context (remove-if (lambda (p) (find p *PRIVATE-KEYS*)) (content-text (format nil "~{~A~%~}" content))
(push (cons :page-content page-content) page) :key 'car))) (parsed-header (yaml:parse header-text))
(page-context
(with-open-file (output-stream output-path (when parsed-header
:direction :output (loop for k being each hash-key of parsed-header
:if-exists :supersede) using (hash-value v)
(let ((mustache:*load-path* (cons *PAGES-DIR* mustache:*load-path*)) collect (cons k v)))))
(mustache:*default-pathname-type* "html")) (with-open-file (output-stream output-path
(mustache:render template-path (append page-context *GLOBAL-CONTEXT*) :direction :output
output-stream))))) :if-exists :supersede)
(mustache:render template-path (append (acons :page-content content-text page-context) *GLOBAL-CONTEXT*)
output-stream))))))
(defun process-pages (pages) (defun process-pages (pages)
(format t "Processing 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