- "Helper to format a field NAME and VALUE."
- (if value (format "%s: %s\n" name value) ""))
-
-(defun pelican-markdown-header (title date status category tags slug)
- "Generate a Pelican Markdown header.
-
-All parameters but TITLE may be nil to omit them. DATE may be a
-string or 't to use the current date and time."
- (let ((title (format "Title: %s\n" title))
- (status (pelican-field "Status" status))
- (category (pelican-field "Category" category))
- (tags (pelican-field "Tags" tags))
- (slug (pelican-field "Slug" slug))
- (date (if date (format "Date: %s\n"
- (if (stringp date) date
- (pelican-timestamp-now)))
- "")))
- (concat title date status tags category slug "\n")))
-
-(defun pelican-rst-header (title date status category tags slug)
- "Generate a Pelican reStructuredText header.
-
-All parameters but TITLE may be nil to omit them. DATE may be a
-string or 't to use the current date and time."
- (let ((title (format "%s\n%s\n\n" title
- (make-string (string-width title) ?#)))
- (status (pelican-field ":status" status))
- (category (pelican-field ":category" category))
- (tags (pelican-field ":tags" tags))
- (slug (pelican-field ":slug" slug))
- (date (if date (format ":date: %s\n"
- (if (stringp date) date
- (pelican-timestamp-now)))
- "")))
- (concat title date status tags category slug "\n")))
+ "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-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)
+ (concat title "\n" (make-string (string-width title) ?#) "\n"))
+ (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"))