Skip to content

Instantly share code, notes, and snippets.

@phred
Created May 6, 2019 15:33
Show Gist options
  • Save phred/d9b4c1800dd17986973de606e8099602 to your computer and use it in GitHub Desktop.
Save phred/d9b4c1800dd17986973de606e8099602 to your computer and use it in GitHub Desktop.
Exporting posts from a Ghost SQLite database to Pollen https://docs.racket-lang.org/pollen/index.html
#lang racket
(require racket/dict)
(require db)
(define ghost (sqlite3-connect #:database "ghost/content/data/ghost.db"))
(define posts-result
(query ghost "select published_at, slug, title, markdown from posts where status='published'"))
(define posts (rows->dict posts-result #:key "slug" #:value '#("published_at" "title" "markdown")))
(define ensure-directory (lambda (path)
(unless (directory-exists? path)
(make-directory path))
(string->path path)
)
)
(define output (ensure-directory "import"))
(dict-map
posts
(lambda (slug post)
(let ([output-file (build-path output (string-append slug ".html.pmd"))])
(delete-file output-file)
(display-to-file (format "#lang pollen\n\n◊headline{~a}\n\n~a" (vector-ref post 1) (vector-ref post 2)) output-file)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment