Created
May 6, 2020 21:43
-
-
Save snorremd/47ed099fa0b2bc3ef41be75b95e42e6e to your computer and use it in GitHub Desktop.
Takes a ghost export file on stdin. Writes markdown files with headers in ./
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bb | |
(def md-head-template | |
"--- | |
path: \"/blog/%s\" | |
date: \"%s\" | |
title: \"%s\" | |
--- | |
") | |
(defn post->date | |
[post] | |
(first (str/split (:created_at post) #" "))) | |
(defn post->md | |
[post] | |
(str | |
(format md-head-template | |
(:slug post) | |
(post->date post) | |
(:title post)) | |
"\n" | |
(:plaintext post))) | |
(def posts (-> *in* | |
io/reader | |
(json/parse-stream true) | |
:db | |
first | |
:data | |
:posts | |
(as-> posts (filter #(not= (:status %) "draft") posts)))) | |
(doseq [post posts] | |
(spit (str "./" | |
(post->date post) | |
"-" | |
(:slug post) ".md") | |
(post->md post))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment