feat(frontmatter): separate frontmatter & content
Added function to read a file and separate frontmatter from content.
This commit is contained in:
parent
9be455b2b7
commit
6cf6bd2c0a
|
@ -1,3 +1,6 @@
|
|||
---
|
||||
title: This is a test document
|
||||
---
|
||||
# Test document
|
||||
|
||||
This is a test document that we should be able to convert to HTML.
|
||||
|
|
|
@ -2,4 +2,21 @@
|
|||
(:use :cl))
|
||||
(in-package :homestead)
|
||||
|
||||
;; blah blah blah.
|
||||
(defun separate-content-and-frontmatter (file-path)
|
||||
(with-open-file (stream file-path)
|
||||
(let* ((line (read-line stream nil nil))
|
||||
(in-frontmatter (string= line "---"))
|
||||
frontmatter
|
||||
content)
|
||||
(setf frontmatter (with-output-to-string (s)
|
||||
(when in-frontmatter
|
||||
(loop while in-frontmatter do
|
||||
(setf line (read-line stream nil nil))
|
||||
(if (string= line "---")
|
||||
(setf in-frontmatter nil)
|
||||
(write-line line s))))))
|
||||
(setf content (with-output-to-string (s)
|
||||
(loop with end-of-file = nil
|
||||
while (setf line (read-line stream nil end-of-file))
|
||||
do (write-line line s))))
|
||||
(list frontmatter content))))
|
||||
|
|
Loading…
Reference in New Issue