Explorar o código

Implement DEPLOY, package updates, minor tweaks.

Brit Butler %!s(int64=13) %!d(string=hai) anos
pai
achega
a698389c42
Modificáronse 5 ficheiros con 32 adicións e 38 borrados
  1. 2 0
      .gitignore
  2. 16 16
      src/coleslaw.lisp
  3. 1 1
      src/git.lisp
  4. 7 7
      src/packages.lisp
  5. 6 14
      src/themes.lisp

+ 2 - 0
.gitignore

@@ -2,3 +2,5 @@
2 2
 *.fasl
3 3
 ignore/
4 4
 generated/
5
+.curr
6
+.prev

+ 16 - 16
src/coleslaw.lisp

@@ -11,38 +11,38 @@
11 11
    (title :initarg :title :initform "" :accessor title)
12 12
    (theme :initarg :theme :initform "hyde" :accessor theme)))
13 13
 
14
-(defparameter *config* nil
15
-  "A variable to store the blog configuration and plugin settings.")
16
-
17 14
 (defun app-path (path)
18 15
   "Take a relative PATH and return the corresponding pathname beneath coleslaw."
19 16
   (merge-pathnames path coleslaw-conf:*basedir*))
20 17
 
21
-(defun load-config ()
22
-  nil)
23
-
24
-(defun exit-handler ()
25
-  nil)
26
-
27 18
 (defun compile-blog ()
28 19
   (let ((staging #p"/tmp/coleslaw/"))
29 20
     ; TODO: More incremental compilation? Don't regen whole blog unnecessarily.
30 21
     (if (probe-file staging)
31
-        (iolib.os:delete-files staging :recursive t)
22
+        (delete-files staging :recursive t)
32 23
         (ensure-directories-exist staging))
33 24
     (with-current-directory staging
34 25
       (let ((css-dir (app-path (format nil "themes/~a/css/" (theme *config*))))
35 26
             (static-dir (merge-pathnames "static/" (repo *config*))))
36 27
         (dolist (dir (list css-dir static-dir))
37
-          (iolib.os:run-program "cp" `("-R" ,dir "."))))
28
+          (run-program "cp" `("-R" ,dir "."))))
38 29
       (render-posts)
39 30
       (render-indices))
40 31
     (deploy staging)))
41 32
 
33
+(defun deploy (dir)
34
+  "Deploy DIR, updating the .prev and .curr symlinks."
35
+  (let ((new-build (app-path (format nil "generated/~a" (get-universal-time)))))
36
+    (run-program "mv" (list dir (app-path new-build)))
37
+    (when (probe-file (app-path ".prev"))
38
+      (delete-files (read-symlink (app-path ".prev")) :recursive t))
39
+    (when (probe-file (app-path ".curr"))
40
+      (run-program "ln" (list "-sfn" (read-symlink (app-path ".curr")) ".prev")))
41
+    (run-program "ln" (list "-sfn" new-build ".curr")))
42
+  (setf (last-published) (last-commit)))
43
+
42 44
 (defun main ()
43 45
   (load-config)
44
-  (unwind-protect
45
-       (loop do (if (blog-update-p)
46
-                    (compile-blog)
47
-                    (sleep (interval *config*))))
48
-    (exit-handler)))
46
+  (loop do (if (blog-update-p)
47
+               (compile-blog)
48
+               (sleep (interval *config*)))))

+ 1 - 1
src/git.lisp

@@ -4,7 +4,7 @@
4 4
   "Retrieve the SHA1 hash of the most recent blog commit."
5 5
   (multiple-value-bind (pid stdout stderr)
6 6
       (with-current-directory (repo *config*)
7
-        (iolib.os:run-program "git" '("log" "-n 1")))
7
+        (run-program "git" '("log" "-n 1")))
8 8
     (cl-ppcre:scan-to-strings "[0-9a-f]{40}" stdout)))
9 9
 
10 10
 (defun last-published ()

+ 7 - 7
src/packages.lisp

@@ -1,13 +1,16 @@
1 1
 (defpackage :coleslaw
2 2
   (:use :cl :closure-template)
3 3
   (:import-from :iolib.os #:with-current-directory
4
-                          #:*temporary-directory*)
4
+                          #:delete-files
5
+                          #:read-symlink
6
+                          #:run-program)
5 7
   (:export ;; themes
6
-           #:*current-theme*
7
-           #:*theme-dir*
8 8
            #:add-injection
9 9
            #:remove-injection
10 10
 
11
+           ;; plugins
12
+           #:load-plugins
13
+
11 14
            ;; posts
12 15
            #:make-post
13 16
            #:add-post
@@ -32,7 +35,4 @@
32 35
            #:index-url
33 36
 
34 37
            #:index-id
35
-           #:index-posts
36
-
37
-           ;; plugins
38
-           #:load-plugins))
38
+           #:index-posts))

+ 6 - 14
src/themes.lisp

@@ -1,27 +1,19 @@
1 1
 (in-package :coleslaw)
2 2
 
3
-(defparameter *current-theme* "hyde"
4
-  "The name of a directory containing templates for HTML generation.")
5
-
6
-(defparameter *theme-dir* (merge-pathnames
7
-                           (concatenate 'string "themes/" *current-theme* "/")
8
-                           (asdf:system-source-directory 'coleslaw))
9
-  "The directory containing the current theme and other site templates.")
10
-
11 3
 (defgeneric add-injection (str location)
12 4
   (:documentation "Add STR to the list of elements injected in LOCATION."))
13 5
 
14 6
 (defgeneric remove-injection (str location)
15 7
   (:documentation "Remove STR from the list of elements injected in LOCATION."))
16 8
 
17
-(defun theme-package (&key (name *current-theme*))
9
+(defun theme-package (&key (name (theme *config*)))
18 10
   (find-package (string-upcase (concatenate 'string "coleslaw.theme." name))))
19 11
 
20
-(defun compile-theme (&key (theme-dir *theme-dir*))
21
-  (loop for file in (cl-fad:list-directory theme-dir) do
22
-       (let ((extension (pathname-type file)))
23
-         (when (and extension (string= extension "tmpl"))
24
-           (compile-template :common-lisp-backend file)))))
12
+(defun compile-theme (&key (theme-dir (app-path (theme *config*))))
13
+  (loop for file in (iolib.os:list-directory theme-dir)
14
+     do (let ((extension (pathname-type file)))
15
+          (when (and extension (string= extension "tmpl"))
16
+            (compile-template :common-lisp-backend file)))))
25 17
 
26 18
 ;; DOCUMENTATION
27 19
 ;; A theme directory should be named after the theme and contain *.tmpl files