about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2020-08-02 03:33:28 +0530
committerArun Isaac2020-08-03 01:24:12 +0530
commit8532a822124904e70618818dfaf12f09752e8e9f (patch)
tree0277c8f72895467d49afbce0bd5924e46e67848e
parent172a5413ba2e786b3b7d8e8d1793e6ff05eb96df (diff)
downloadennum-8532a822124904e70618818dfaf12f09752e8e9f.tar.gz
ennum-8532a822124904e70618818dfaf12f09752e8e9f.tar.lz
ennum-8532a822124904e70618818dfaf12f09752e8e9f.zip
Replace ennum--expand-relative with ennum--file-join.
* ennum.el (ennum--file-join): New function.
(ennum--expand-relative): Delete function.
(ennum-posts, ennum-publish-generic, ennum-publish-image,
ennum-publish-link, ennum-publish): Replace ennum--expand-relative
with ennum--file-join.
-rw-r--r--ennum.el40
1 files changed, 23 insertions, 17 deletions
diff --git a/ennum.el b/ennum.el
index 855aade..c9d78a9 100644
--- a/ennum.el
+++ b/ennum.el
@@ -186,7 +186,7 @@ respectively by - and _, and the pad character = is optional."
                  (lambda (file)
                    (when (string= (file-name-extension file) "org")
                      (ennum-read-post
-                      (ennum--expand-relative file (ennum-setting :posts-directory)))))
+                      (ennum--file-join (ennum-setting :posts-directory) file))))
                  (ennum-directory-files (ennum-setting :posts-directory)))))
            ;; Group posts by translation group.
            (seq-group-by
@@ -357,7 +357,9 @@ result as a string."
 
 (defun ennum-publish-generic (other-files-directory file)
   (ennum-exp
-   (let ((interned-file (ennum-input (ennum-intern (ennum--expand-relative file other-files-directory))))
+   (let ((interned-file
+          (ennum-input (ennum-intern
+                        (ennum--file-join other-files-directory file))))
          (output-file
           (pcase (file-name-extension file)
             ("org" (ennum--org-output-filename file))
@@ -529,8 +531,12 @@ result as a string."
           (file-name-sans-extension image)
           width (file-name-extension image)))
 
-(defun ennum--expand-relative (name directory)
-  (concat (file-name-as-directory directory) name))
+(defun ennum--file-join (&rest components)
+  (string-join
+   (seq-map (lambda (component)
+              (string-remove-suffix "/" (file-name-as-directory component)))
+            components)
+   "/"))
 
 (defun ennum-publish-image (image width)
   (ennum-exp
@@ -539,10 +545,10 @@ result as a string."
      (ennum-image-optimize-image
       (ennum-image-resize-image
        input-image
-       (ennum--expand-relative
+       (ennum--file-join
+        (ennum-setting :images-directory)
         (ennum-image-output-filename
-         (file-name-nondirectory input-image) width)
-        (ennum-setting :images-directory))
+         (file-name-nondirectory input-image) width))
        width)))))
 
 (defun ennum-publish-copy (file)
@@ -577,23 +583,23 @@ if DESTINATION already exists."
     ('image
      (seq-map (lambda (width)
                 (ennum-publish-image
-                 (ennum--expand-relative (ennum-link-path link)
-                                         (ennum-setting :images-directory))
+                 (ennum--file-join (ennum-setting :images-directory)
+                                   (ennum-link-path link))
                  width))
               (list (ennum-setting :default-image-width)
                     (ennum-setting :image-link-width))))
     ('static
      (list
       (ennum-publish-copy
-       (ennum--expand-relative (ennum-link-path link)
-                               (ennum-setting :static-directory)))))
+       (ennum--file-join (ennum-setting :static-directory)
+                         (ennum-link-path link)))))
     ('video
      (seq-map 'ennum-publish-copy
               (list
-               (ennum--expand-relative (ennum-link-path link)
-                                       (ennum-setting :video-directory))
-               (ennum--expand-relative (ennum-video-link-poster link)
-                                       (ennum-setting :images-directory)))))))
+               (ennum--file-join (ennum-setting :video-directory)
+                                 (ennum-link-path link))
+               (ennum--file-join (ennum-setting :images-directory)
+                                 (ennum-video-link-poster link)))))))
 
 (defmacro ennum-with-current-directory (directory &rest body)
   "Change to DIRECTORY, evaluate BODY and restore the current
@@ -660,14 +666,14 @@ as keys. Keys are compared using `equal'."
                  (seq-map
                   (pcase-lambda (`(,tongue . ,posts))
                     (ennum-publish-index
-                     (ennum--expand-relative tag (ennum-setting :tag-directory))
+                     (ennum--file-join (ennum-setting :tag-directory) tag)
                      tag posts-per-page posts))
                   (seq-group-by 'ennum-post-language posts)))
                (ennum-many-to-many-group-by 'ennum-post-tags posts))
               ;; Publish thumbnails
               (seq-map (lambda (image)
                          (ennum-publish-image
-                          (ennum--expand-relative image (ennum-setting :images-directory))
+                          (ennum--file-join (ennum-setting :images-directory) image)
                           (ennum-setting :thumbnail-image-width)))
                        (ennum--filter-map 'ennum-post-thumbnail posts))
               ;; Publish other files