Commit 11d4db3d authored by Erik Huelsmann's avatar Erik Huelsmann

Integrate static asset deployment into Lisp code

parent 47316678
...@@ -5,7 +5,7 @@ serve: ...@@ -5,7 +5,7 @@ serve:
static: static:
mkdir -p output/static mkdir -p output/static
cp -rf content/static/* output/static # cp -rf content/static/* output/static
favicon: favicon:
cp content/favicon.ico output/ cp content/favicon.ico output/
......
;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(in-package :cl-site) (in-package :cl-site)
(defparameter *LAYOUT-DIR* (asdf:system-relative-pathname :cl-site "layout/templates/") (defparameter *LAYOUT-DIR* (asdf:system-relative-pathname :cl-site "layout/templates/")
"Pathname for location of template files.") "Pathname for location of template files.")
(defparameter *OUTPUT-DIR* (asdf:system-relative-pathname :cl-site "output/") (defparameter *OUTPUT-DIR* (asdf:system-relative-pathname :cl-site "output/")
"Pathname where the generated output should be written to.") "Pathname where the generated output should be written to.")
;; @TO-DO: store layout name as global, generate js/css pathnames from it. ;; @TO-DO: store layout name as global, generate js/css pathnames from it.
;; (More template-related variables may go here in the future) ;; (More template-related variables may go here in the future)
(defparameter *DEFAULT-PAGE-TEMPLATE* "layout_2018.html" (defparameter *DEFAULT-PAGE-TEMPLATE* "layout_2018.html"
"Default template to use unless another is explicitly specified.") "Default template to use unless another is explicitly specified.")
;; @TO-DO: replace this with better css preprocessing. ;; @TO-DO: replace this with better css preprocessing.
(defparameter *STYLES-DIR* (asdf:system-relative-pathname :cl-site "layout/css/") (defparameter *STYLES-DIR* (asdf:system-relative-pathname :cl-site "layout/css/")
"Pathname for location and list of styles.") "Pathname for location and list of styles.")
(defparameter *STYLES* (defparameter *STYLES*
(list "layout_2018.css") (list "layout_2018.css")
"A list of strings representing relative filenames.") "A list of strings representing relative filenames.")
;; JS files - separate from static files, because they are processed differently ;; JS files - separate from static files, because they are processed differently
;; within the template. ;; within the template.
(defparameter *SCRIPTS-DIR* (asdf:system-relative-pathname :cl-site "layout/js/") (defparameter *SCRIPTS-DIR* (asdf:system-relative-pathname :cl-site "layout/js/")
"Pathname for location and list of scripts.") "Pathname for location and list of scripts.")
(defparameter *SCRIPTS* (defparameter *SCRIPTS*
(list "scripts.js") (list "scripts.js")
"A list of strings representing relative filenames.") "A list of strings representing relative filenames.")
;; General static files - images etc ;; General static files - images etc
(defparameter *STATIC-DIR* (asdf:system-relative-pathname :cl-site "layout/static/") (defparameter *STATIC-DIR* (asdf:system-relative-pathname :cl-site "content/static/")
"Pathname for location of static files.") "Pathname for location of static files.")
;; The only REQUIRED field is :content which must be the filename of the page content ;; The only REQUIRED field is :content which must be the filename of the page content
;; The :content field will NOT be sent to the template. ;; The :content field will NOT be sent to the template.
;; @TO-DO: store fields within content files and parse them out. ;; @TO-DO: store fields within content files and parse them out.
(defparameter *PAGES-DIR* (asdf:system-relative-pathname :cl-site "content/") (defparameter *PAGES-DIR* (asdf:system-relative-pathname :cl-site "content/")
"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 ;; Extra context for pages
(defparameter *PAGE-CONTEXT* (defparameter *PAGE-CONTEXT*
`(("about.html" ((:title . "Common-Lisp.net | About"))) `(("about.html" ((:title . "Common-Lisp.net | About")))
("index.html" ((:title . "Welcome to Common-Lisp.net!"))) ("index.html" ((:title . "Welcome to Common-Lisp.net!")))
("faq.html" ((:title . "Frequently asked questions"))) ("faq.html" ((:title . "Frequently asked questions")))
("gitlab-migration-repository-mapping.html" ((:title . "GitLab migration"))) ("gitlab-migration-repository-mapping.html" ((:title . "GitLab migration")))
("gitlab-migration-status.html" ((:title . "Migration to GitLab"))) ("gitlab-migration-status.html" ((:title . "Migration to GitLab")))
("independent-lists.html" ((:title . "Independent Mailing Lists"))) ("independent-lists.html" ((:title . "Independent Mailing Lists")))
("orphaned-mailing-lists.html" ((:title . "Orphaned mailing lists"))) ("orphaned-mailing-lists.html" ((:title . "Orphaned mailing lists")))
("orphaned-projects.html" ((:title . "Orphaned projects"))) ("orphaned-projects.html" ((:title . "Orphaned projects")))
("phub.html" ((:title . "Projects"))) ("phub.html" ((:title . "Projects")))
("project-intro.html" ((:title . "Project Hosting"))))) ("project-intro.html" ((:title . "Project Hosting")))))
(defun page-context (filename) (defun page-context (filename)
(cadr (assoc filename *page-context* :test 'equalp))) (cadr (assoc filename *page-context* :test 'equalp)))
(defun page-title (filename) (defun page-title (filename)
(or (cdr (assoc :title (page-context filename))) (or (cdr (assoc :title (page-context filename)))
(format nil "Common-Lisp.net | ~a" (format nil "Common-Lisp.net | ~a"
(string-capitalize (string-capitalize
(pathname-name (pathname filename)))))) (pathname-name (pathname filename))))))
(defparameter *PAGES* (defparameter *PAGES*
(mapcar (lambda (p) (mapcar (lambda (p)
(let ((context (let ((context
(append (list (cons :content (file-namestring p))) (append (list (cons :content (file-namestring p)))
(page-context (file-namestring p))))) (page-context (file-namestring p)))))
(when (not (assoc :title context)) (when (not (assoc :title context))
(push (cons :title (page-title (file-namestring p))) (push (cons :title (page-title (file-namestring p)))
context)) context))
context)) context))
(directory (make-pathname :defaults *PAGES-DIR* (directory (make-pathname :defaults *PAGES-DIR*
:name :wild :name :wild
:type "html"))) :type "html")))
"Each page is an alist containing info to be sent to the template via the context.") "Each page is an alist containing info to be sent to the template via the context.")
;; Initialize global context (will be appended to all individual page contexts) ;; Initialize global context (will be appended to all individual page contexts)
;; Used to store things like stylesheets, etc... ;; Used to store things like stylesheets, etc...
(defparameter *GLOBAL-CONTEXT* ()) (defparameter *GLOBAL-CONTEXT* ())
This diff is collapsed.
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