From 6456c8b47937b555be8620379e73292a9300a848 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Mon, 7 Aug 2017 17:45:56 +0200 Subject: [PATCH] Simplify slug generation and page detection. --- pelican-mode.el | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/pelican-mode.el b/pelican-mode.el index 1de4db3..60089cd 100644 --- a/pelican-mode.el +++ b/pelican-mode.el @@ -341,22 +341,20 @@ has no status." (defun pelican-mode-page-p () "Return non-nil the current buffer is a Pelican page." - (when-let (pelican-mode-base (pelican-mode-find-root)) - (let* ((relative (file-relative-name buffer-file-name pelican-mode-base)) - (components (split-string relative "/"))) - (equal "pages" (cadr components))))) + (string-match-p + "^[^/]+/pages/" + (file-relative-name + (abbreviate-file-name (or (buffer-file-name) (buffer-name))) + (pelican-mode-find-root)))) (defun pelican-mode-default-slug () - "Generate a Pelican article/page slug for the current buffer." - (if-let ((pelican-mode-base (pelican-mode-find-root)) - (file-name (file-name-sans-extension buffer-file-name))) - (let* ((relative (file-relative-name file-name pelican-mode-base)) - (components (cdr (split-string relative "/"))) - (components (if (string= "pages" (car components)) - (cdr components) components))) - (mapconcat 'identity components "/")) - (when-let (file-name (file-name-sans-extension buffer-file-name)) - (file-name-base file-name)))) + "Generate a Pelican slug for the current buffer." + (file-name-sans-extension + (replace-regexp-in-string + "^[^/]+/\\(?:pages/\\)?" "" + (file-relative-name + (abbreviate-file-name (or (buffer-file-name) (buffer-name))) + (pelican-mode-find-root))))) (defun pelican-mode-find-root () "Return the root of the buffer's Pelican site, or nil." -- 2.30.2