Recently Written · git

coleslaw

Emacs mode for the "Coleslaw" site generator written in Common Lisp.

git clone https://github.com/equwal/coleslaw

Log | Files | Refs


commit 656401df71c005d30ae591a717e486aa9197d26f
Spenser Truex <web@spensertruex.com>
2020-03-24 15:12:11 -0700

Optional extension file extensions for posts and index

I wanted posts to have no extension (via :page-ext), so I had to allow for
:page-ext "" to work, and without inserting a dot at the end of my files. To
allow for index.html when :page-ext is not "html", :index-ext "html" in the
.coleslawrc is supported.

 src/coleslaw.lisp  |  4 ++--
 src/config.lisp    | 16 ++++++++++++----
 src/documents.lisp | 10 +++++++++-
 3 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/src/coleslaw.lisp b/src/coleslaw.lisp
index 1517c66..f4bfeee 100644
--- a/src/coleslaw.lisp
+++ b/src/coleslaw.lisp
@@ -40,8 +40,8 @@
       (publish ctype))
     (do-subclasses (itype index)
       (publish itype))
-    (update-symlink (format nil "index.~A" (page-ext *config*))
-                    (format nil "1.~A" (page-ext *config*)))))
+    (update-symlink (format nil "index.~A" (index-ext *config*))
+                    (format nil "1~A" (page-ext *config*)))))
 
 (defgeneric deploy (staging)
   (:documentation "Deploy the STAGING build to the directory specified in the config.")
diff --git a/src/config.lisp b/src/config.lisp
index 9d5a45f..53f0fe4 100644
--- a/src/config.lisp
+++ b/src/config.lisp
@@ -9,7 +9,7 @@
    (feeds           :initarg :feeds          :reader feeds)
    (lang            :initarg :lang           :reader lang)
    (license         :initarg :license        :reader license)
-   (page-ext        :initarg :page-ext       :reader page-ext)
+   (page-ext        :initarg :page-ext       :reader page-ext-intolerant)
    (plugins         :initarg :plugins        :reader plugins)
    (repo            :initarg :repo           :accessor repo-dir)
    (routing         :initarg :routing        :reader routing)
@@ -17,7 +17,8 @@
    (sitenav         :initarg :sitenav        :reader sitenav)
    (staging-dir     :initarg :staging-dir    :reader staging-dir)
    (theme           :initarg :theme          :reader theme)
-   (title           :initarg :title          :reader title))
+   (title           :initarg :title          :reader title)
+   (index-ext       :initarg :index-ext      :reader index-ext))
   (:default-initargs
    :feeds        nil
    :license      nil
@@ -26,10 +27,17 @@
    :excerpt-sep  "<!--more-->"
    :charset      "UTF-8"
    :lang         "en"
-   :page-ext     "html"
+   :page-ext     #1="html"
    :separator    ";;;;;"
-   :staging-dir  "/tmp/coleslaw"))
+   :staging-dir  "/tmp/coleslaw"
+   :index-ext    #1#))
 
+(defun page-ext (config)
+  "Get page extension, and allow for an extensionless system."
+  (let ((ext (page-ext-intolerant config)))
+    (if (string= ext "")
+        ""
+        (concatenate 'string "." ext))))
 (defun dir-slot-reader (config name)
   "Take CONFIG and NAME, and return a directory pathname for the matching SLOT."
   (ensure-directory-pathname (slot-value config name)))
diff --git a/src/documents.lisp b/src/documents.lisp
index b90d299..0bb64c6 100644
--- a/src/documents.lisp
+++ b/src/documents.lisp
@@ -42,7 +42,15 @@ is provided, it overrides the route used."
       (error "No routing method found for: ~A" class-name))
     (let* ((result (format nil route unique-id))
            (type (or (pathname-type result) (page-ext *config*))))
-      (make-pathname :type type :defaults result))))
+      (make-pathname :name (pathname-name result)
+                     :type (when (string/= type "")
+                             (if (or (string-equal "index"
+                                                   (pathname-name result))
+                                     (string-equal "1"
+                                                   (pathname-name result)))
+                                 (index-ext *config*)
+                                 type))
+                     :defaults result))))
 
 (defun get-route (doc-type)
   "Return the route format string for DOC-TYPE."