- (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)))))
-
-(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 ,@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."
- (interactive
- (list (read-string "Page title: ")
- (y-or-n-p "Hidden? ")))
- (apply #'pelican-mode-insert-header
- `(,title ,@pelican-mode-default-page-fields
- :hidden ,(when hidden "hidden"))))
-
-(defun pelican-mode-insert-auto-header ()
- "Insert a Pelican header for a page or article."
- (interactive)
- (call-interactively
- (if (pelican-mode-page-p)
- #'pelican-mode-insert-page-header
- #'pelican-mode-insert-draft-article-header)))
-
-(defun pelican-mode-set-field (field value)
- "Set FIELD to VALUE."
- (interactive "sField: \nsValue: ")
- (save-excursion
- (goto-char 0)
- (when (and (derived-mode-p 'rst-mode)
- (re-search-forward "^#" nil t))
- (forward-line 2))
- (if (re-search-forward (concat "^" (pelican-mode-field field ".+*")) nil t)
- (replace-match (pelican-mode-field field value))
- (when value
- (re-search-forward "^$")
- (replace-match (pelican-mode-field field value))))))