-(defun pelican-mode-field (name value)
- "Format a line for a field NAME with a VALUE.
-
-NAME may be a string or a symbol; if it is a symbol, the
-symbol name is used (removing a leading ':' if present).
-
-VALUE may be any value; except for the following special values,
-the unquoted printed representation of it is used:
-
-- `now' means the current time; see `pelican-mode-timestamp'.
-
-- `slug' means the file's path relative to the document root sans
- extension; see `pelican-mode-default-slug'.
-
-- nil or an empty strings means return an empty string, without
- any name or value."
- (setq value (pcase value
- ('now (pelican-mode-timestamp))
- ('slug (pelican-mode-default-slug))
- ('"" nil)
- (_ value)))
- (when (symbolp name)
- (setq name (string-remove-prefix ":" (symbol-name name))))
- (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-mode-rst-title (title)
- "Format a reStructureText version of TITLE."
- (concat title "\n" (make-string (string-width title) ?#) "\n\n"))
-
-(defun pelican-mode-title (title)
- "Format a TITLE for the current document, according to major mode."
- (cond ((derived-mode-p 'markdown-mode)
- (pelican-mode-field "title" title))
- ((derived-mode-p 'rst-mode)
- (pelican-mode-rst-title title))
- (t (error "Unsupported major mode %S" major-mode))))
-
-(defun pelican-mode-header (title &rest fields)
- "Generate a Pelican header for an article with a TITLE and metadata FIELDS."
- (concat (pelican-mode-title title)
- (mapconcat (apply-partially #'apply #'pelican-mode-field)
- (seq-partition fields 2) "")
- "\n"))
-
-(defun pelican-mode-insert-header (title &rest fields)
- "Insert a Pelican header for an article with a TITLE and metadata FIELDS."
- (save-excursion
- (goto-char 0)
- (insert (apply #'pelican-mode-header (cons title fields)))))