-(defun pelican-is-markdown ()
- "Check if the buffer is likely using Markdown."
- (derived-mode-p 'markdown-mode))
-
-(defun pelican-field (name value)
- "Format a line for a field NAME with a VALUE."
- (if value
- (cond ((derived-mode-p 'markdown-mode)
- (format "%s: %s\n" (capitalize name) value))
- ((derived-mode-p 'rst-mode)
- (format ":%s: %s\n" (downcase name) value))
- (t (error "Unsupported major mode %S" major-mode)))
- ""))
-
-(defun pelican-rst-title (title)
- "Create a ReSt version of TITLE."
- (concat title "\n" (make-string (string-width title) ?#) "\n\n"))
-
-(defun pelican-title (title)
- "Format a TITLE for the current document, according to major mode."
- (cond ((derived-mode-p 'markdown-mode)
- (pelican-field "title" title))
- ((derived-mode-p 'rst-mode)
- (pelican-rst-title title))
- (t (error "Unsupported major mode %S" major-mode))))
-
-(defun pelican-header (title date status category tags slug)
- "Create a Pelican header."
- ;; TODO: Use a property list (-> alist via seq-partition) instead.
- (when (eq date t)
- (setq date (pelican-timestamp)))
-
- (concat (pelican-title title)
- (pelican-field "date" date)
- (pelican-field "status" status)
- (pelican-field "tags" tags)
- (pelican-field "category" category)
- (pelican-field "slug" slug)
- "\n"))
-
-(defun pelican-insert-draft-post-header (title tags)
- "Insert a Pelican header for a draft post."
- (interactive "sPost title: \nsTags: ")
- (let ((slug (pelican-default-slug)))
- (save-excursion
- (goto-char 0)
- (insert (pelican-header title 't "draft" nil tags slug)))))
-
-(defun pelican-insert-page-header (title hidden)
- "Insert a Pelican header for a page."
+(defun pelican-mode-insert-header (&rest fields)
+ "Insert a Pelican header for an article with metadata FIELDS."
+ (mapc (apply-partially #'apply #'pelican-mode-set-field)
+ (seq-partition fields 2)))
+
+(defun pelican-mode-insert-draft-article-header (title tags)
+ "Insert a Pelican header for a draft with a TITLE and TAGS."
+ (interactive "sArticle title: \nsTags: ")
+ (apply #'pelican-mode-insert-header
+ `(:title ,title ,@pelican-mode-default-article-fields :tags ,tags)))
+
+(defun pelican-mode-insert-page-header (title &optional hidden)
+ "Insert a Pelican header for a page with a TITLE, potentially HIDDEN."