Ver código fonte

APP-PATH tweaks, COMPILE-THEME fix.

Brit Butler 13 anos atrás
pai
commit
65d4f349da
4 arquivos alterados com 27 adições e 53 exclusões
  1. 7 16
      src/coleslaw.lisp
  2. 11 0
      src/config.lisp
  3. 2 32
      src/packages.lisp
  4. 7 5
      src/themes.lisp

+ 7 - 16
src/coleslaw.lisp

1
 (in-package :coleslaw)
1
 (in-package :coleslaw)
2
 
2
 
3
-(defclass blog ()
4
-  ((author :initarg :author :initform "" :accessor author)
5
-   (domain :initarg :domain :initform "" :accessor domain)
6
-   (interval :initarg :interval :initform 600 :accessor interval)
7
-   (license :initarg :license :initform "" :accessor license)
8
-   (plugins :initarg :plugins :initform '() :accessor plugins)
9
-   (repo :initarg :repo :initform #p"/" :accessor repo)
10
-   (sitenav :initarg :sitenav :initform "" :accessor sitenav)
11
-   (title :initarg :title :initform "" :accessor title)
12
-   (theme :initarg :theme :initform "hyde" :accessor theme)))
13
-
14
-(defun app-path (path)
15
-  "Take a relative PATH and return the corresponding pathname beneath coleslaw."
16
-  (merge-pathnames path coleslaw-conf:*basedir*))
3
+(defun app-path (path &rest args)
4
+  "Take a relative PATH and return the corresponding pathname beneath coleslaw.
5
+If ARGS is provided, use (apply 'format nil PATH ARGS) as the value of PATH."
6
+  (merge-pathnames (apply 'format nil path args) coleslaw-conf:*basedir*))
17
 
7
 
18
 (defun compile-blog ()
8
 (defun compile-blog ()
19
   (let ((staging #p"/tmp/coleslaw/"))
9
   (let ((staging #p"/tmp/coleslaw/"))
22
         (delete-files staging :recursive t)
12
         (delete-files staging :recursive t)
23
         (ensure-directories-exist staging))
13
         (ensure-directories-exist staging))
24
     (with-current-directory staging
14
     (with-current-directory staging
25
-      (let ((css-dir (app-path (format nil "themes/~a/css/" (theme *config*))))
15
+      (let ((css-dir (app-path "themes/~a/css/" (theme *config*)))
26
             (static-dir (merge-pathnames "static/" (repo *config*))))
16
             (static-dir (merge-pathnames "static/" (repo *config*))))
27
         (dolist (dir (list css-dir static-dir))
17
         (dolist (dir (list css-dir static-dir))
28
           (run-program "cp" `("-R" ,dir "."))))
18
           (run-program "cp" `("-R" ,dir "."))))
36
 
26
 
37
 (defun deploy (dir)
27
 (defun deploy (dir)
38
   "Deploy DIR, updating the .prev and .curr symlinks."
28
   "Deploy DIR, updating the .prev and .curr symlinks."
39
-  (let ((new-build (app-path (format nil "generated/~a" (get-universal-time)))))
29
+  (let ((new-build (app-path "generated/~a" (get-universal-time))))
40
     (run-program "mv" (list dir (namestring new-build)))
30
     (run-program "mv" (list dir (namestring new-build)))
41
     (when (probe-file (app-path ".prev"))
31
     (when (probe-file (app-path ".prev"))
42
       (delete-files (read-symlink (app-path ".prev")) :recursive t))
32
       (delete-files (read-symlink (app-path ".prev")) :recursive t))
47
 
37
 
48
 (defun main ()
38
 (defun main ()
49
   (load-config)
39
   (load-config)
40
+  (compile-theme)
50
   (loop do (if (blog-update-p)
41
   (loop do (if (blog-update-p)
51
                (compile-blog)
42
                (compile-blog)
52
                (sleep (interval *config*)))))
43
                (sleep (interval *config*)))))

+ 11 - 0
src/config.lisp

1
 (in-package :coleslaw)
1
 (in-package :coleslaw)
2
 
2
 
3
+(defclass blog ()
4
+  ((author :initarg :author :initform "" :accessor author)
5
+   (domain :initarg :domain :initform "" :accessor domain)
6
+   (interval :initarg :interval :initform 600 :accessor interval)
7
+   (license :initarg :license :initform "" :accessor license)
8
+   (plugins :initarg :plugins :initform '() :accessor plugins)
9
+   (repo :initarg :repo :initform #p"/" :accessor repo)
10
+   (sitenav :initarg :sitenav :initform "" :accessor sitenav)
11
+   (title :initarg :title :initform "" :accessor title)
12
+   (theme :initarg :theme :initform "hyde" :accessor theme)))
13
+
3
 (defparameter *config* nil
14
 (defparameter *config* nil
4
   "A variable to store the blog configuration and plugin settings.")
15
   "A variable to store the blog configuration and plugin settings.")
5
 
16
 

+ 2 - 32
src/packages.lisp

4
                           #:delete-files
4
                           #:delete-files
5
                           #:read-symlink
5
                           #:read-symlink
6
                           #:run-program)
6
                           #:run-program)
7
-  (:export ;; themes
8
-           #:add-injection
9
-           #:remove-injection
10
-
11
-           ;; plugins
12
-           #:load-plugins
13
-
14
-           ;; posts
15
-           #:make-post
16
-           #:add-post
17
-           #:remove-post
18
-           #:render-post
19
-           #:find-post
20
-           #:post-url
21
-
22
-           #:post-id
23
-           #:post-title
24
-           #:post-tags
25
-           #:post-date
26
-           #:post-content
27
-           #:post-aliases
28
-
29
-           ;; indices
30
-           #:make-index
31
-           #:add-to-index
32
-           #:remove-from-index
33
-           #:render-index
34
-           #:find-index
35
-           #:index-url
36
-
37
-           #:index-id
38
-           #:index-posts))
7
+  (:import-from :iolib.pathnames #:file-path-namestring)
8
+  (:export #:main))

+ 7 - 5
src/themes.lisp

9
 (defun theme-package (&key (name (theme *config*)))
9
 (defun theme-package (&key (name (theme *config*)))
10
   (find-package (string-upcase (concatenate 'string "coleslaw.theme." name))))
10
   (find-package (string-upcase (concatenate 'string "coleslaw.theme." name))))
11
 
11
 
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)))))
12
+(defun compile-theme (&key (theme-dir (app-path "themes/~a/" (theme *config*))))
13
+  (flet ((maybe-compile (file)
14
+           (let* ((path (merge-pathnames (file-path-namestring file) theme-dir))
15
+                  (extension (pathname-type path)))
16
+             (when (and extension (string= extension "tmpl"))
17
+               (compile-template :common-lisp-backend path)))))
18
+    (iolib.os:mapdir #'maybe-compile theme-dir)))
17
 
19
 
18
 ;; DOCUMENTATION
20
 ;; DOCUMENTATION
19
 ;; A theme directory should be named after the theme and contain *.tmpl files
21
 ;; A theme directory should be named after the theme and contain *.tmpl files