diff options
| author | Craig Jennings <c@cjennings.net> | 2026-02-14 00:45:55 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-02-14 00:45:55 -0600 |
| commit | ebd8b2ce83941386b196e663d8f8ba83d7ce44c1 (patch) | |
| tree | dba9b2da35a60c44f039495fbab565a0500c4373 /modules/hugo-config.el | |
| parent | 78c3ef3c2008f72f9e46f30447c68d627bd693cd (diff) | |
test: add ERT coverage for modeline-config and hugo-config
Add 67 tests across 6 new test files for modeline and hugo modules.
Refactor hugo-config: extract post-file-path and post-template helpers
from interactive new-post function for testability. Update todo.org
with test audit (31 modules), priority adjustments, and task cleanup.
Diffstat (limited to 'modules/hugo-config.el')
| -rw-r--r-- | modules/hugo-config.el | 39 |
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))) |
