deft icon indicating copy to clipboard operation
deft copied to clipboard

Read jekyll style Front Matter for titles and other metadata

Open jessebmiller opened this issue 6 years ago • 2 comments

It would be sweet to use deft for writing markdown files for static sites.

The titles and other metadata for these files however are in Front Matter (YAML) rather than on the first line.

---
layout: post
title: Write Your Blog Using Deft!!!
---

Start of the post
...

jessebmiller avatar Feb 24 '18 19:02 jessebmiller

Seconding this. I couldn't work around this by providing a new deft-parse-title-function as that function is only passed the first line, and I couldn't get it to work adding advice to deft-parse-title. This feature would be great!

bcclaywell avatar Jun 25 '20 15:06 bcclaywell

For anyone from the future, here's what more or less works for me:

(defun my-strip-front-matter (contents)
  (replace-regexp-in-string "^---\\(?:\n.*\\)*---.*$" "" contents))

(defun my-deft-parse-title-wrapper (f file contents)
  (let ((new-contents (my-strip-front-matter contents)))
    (funcall f file new-contents)))

(defun my-deft-parse-summary-wrapper (f contents title)
  (let ((new-contents (my-strip-front-matter contents)))
    (funcall f new-contents title)))

(advice-add 'deft-parse-title :around 'my-deft-parse-title-wrapper)
(advice-add 'deft-parse-summary :around 'my-deft-parse-summary-wrapper)

bcclaywell avatar Jun 26 '20 18:06 bcclaywell