summaryrefslogtreecommitdiff
path: root/modules/hugo-config.el
diff options
context:
space:
mode:
Diffstat (limited to 'modules/hugo-config.el')
-rw-r--r--modules/hugo-config.el39
1 files changed, 25 insertions, 14 deletions
diff --git a/modules/hugo-config.el b/modules/hugo-config.el
index 8bc2cef2..33245fd4 100644
--- a/modules/hugo-config.el
+++ b/modules/hugo-config.el
@@ -34,31 +34,42 @@
;; ----------------------------- Hugo Blog Functions ---------------------------
+(defun cj/hugo--post-file-path (title)
+ "Return the file path for a Hugo post with TITLE.
+Generates a slug from TITLE using `org-hugo-slug' and returns
+the full path under `cj/hugo-content-org-dir'.
+Assumes ox-hugo is already loaded (via use-package declaration above)."
+ (let ((slug (org-hugo-slug title)))
+ (expand-file-name (concat slug ".org") cj/hugo-content-org-dir)))
+
+(defun cj/hugo--post-template (title date)
+ "Return the Org front matter template for a Hugo post.
+TITLE is the post title, DATE is the date string (YYYY-MM-DD)."
+ (format "#+hugo_base_dir: ../../
+#+hugo_section: log
+#+hugo_auto_set_lastmod: t
+#+title: %s
+#+date: %s
+#+hugo_tags:
+#+hugo_draft: true
+#+hugo_custom_front_matter: :description \"\"
+
+" title date))
+
(defun cj/hugo-new-post ()
"Create a new Hugo blog post as a standalone Org file.
Prompts for title, generates the slug filename, and opens the
new file with Hugo front matter keywords pre-filled."
(interactive)
- (require 'ox-hugo)
(let* ((title (read-from-minibuffer "Post Title: "))
- (slug (org-hugo-slug title))
- (date (format-time-string "%Y-%m-%d"))
- (file (expand-file-name (concat slug ".org") cj/hugo-content-org-dir)))
+ (file (cj/hugo--post-file-path title))
+ (date (format-time-string "%Y-%m-%d")))
(when (file-exists-p file)
(user-error "Post already exists: %s" file))
(unless (file-directory-p cj/hugo-content-org-dir)
(make-directory cj/hugo-content-org-dir t))
(find-file file)
- (insert (format "#+hugo_base_dir: ../../
-#+hugo_section: log
-#+hugo_auto_set_lastmod: t
-#+title: %s
-#+date: %s
-#+hugo_tags:
-#+hugo_draft: true
-#+hugo_custom_front_matter: :description \"\"
-
-" title date))
+ (insert (cj/hugo--post-template title date))
(save-buffer)
(message "New post: %s" file)))