2 minute read

Naver, Egloos, Tistory, Textcube, Wordpress 블로깅 서비스를 거쳐서 지금은 Jekyll을 사용하고 있다. Jekyll과 같은 정적 사이트 생성기는 내가 원하는 에디터로 글을 써서 관리 비용이 적은 정적 블로그를 생성할 수 있는 매력적인 툴이다.

Jekyll은 Markdown으로 글을 써서 HTML을 생성하는 콘텐트 가공하는 프로세스를 가지고 있다. 이게 마음에 안 든다. 내 First-class 마크업 언어는 Org-mode 이기 때문이다. Org-mode로 블로그 포스트를 쓸 방법을 연구했다.

org-ruby 라이브러리로 org 파일을 html로 컨버팅 - 폐기

Jekyll Converters를 사용하면 된다. org 확장자를 가진 파일일 때, html 로 변환하는 Converter를 추가하면 Org-mode로 글을 쓸 수 있다.

module Jekyll
  # Convert org-mode files.
  require 'org-ruby'
  class OrgConverter < Converter
    safe true

    def setup
      # No-op
    end

    def matches(ext)
      ext =~ /org$/i
    end

    def output_ext(ext)
      ".html"
    end

    def convert(content)
      setup
      Orgmode::Parser.new(content).to_html
    end
  end
end

위와 같은 컨버터를 만들어서 _plugins 디렉터리에 만들면 사이트 생성 파이프라인에서 실행한다. wallyqs/org-ruby - github.com 라이브러리를 사용했다.

별도 컨버터를 만들어서 html로 변환하니 테마가 지원하는 기능을 활용하지 못한다. minimal mistakes 테마에서 지원하는 TOC 기능을 사용하지 못한다. org-ruby는 소스 블럭에 pre 태그를 사용하는데 테마에서는 code 태그를 사용해야 예쁘게 보여준다. 하나하나 고쳐나가기보다는 미래를 위해 org-ruby 라이브러리를 사용한 컨버터를 사용하지 않기로 했다.

org 문서를 md로 export - ox-jekyll-lite

방법을 바꿔서 org 문서를 md로 export 하기로 했다. md로 원하는 대로만 export하면 여기서부터는 Jekyll 사이트 생성 파이프라인에 수정 없이 태울 수 있다.

다행히 같은 고민을 한 사람이 있다. peterewills/ox-jekyll-lite - github.com 라이브러리를 찾았다.

#+begin_src elisp :tangle packages.el
  (package! example
    :recipe (:host github :repo "peterewills/ox-jekyll-lite"))
#+end_src

#+begin_src elisp
  (require 'ox-jekyll-lite)
#+end_src

Doom Emacs 설정에 패키지 사용을 추가했다.

org-mode 문서의 Front matter(전문) 역할은 property가 한다. 하지만 나는 그동안 써 온 글이 너무나 많아서 컨버팅하지 않고 yaml 전문을 그대로 사용하게 세팅했다.

(setq org-jekyll-lite-include-yaml-front-matter nil)

포스팅 글에 아래와 같은 전문을 앞에 추가해서 해결했다.

#+begin_export html
---
title: "$title"
date: $now
categories: post
tags:
-
header:
  image: /assets/$now-$title-00.jpg
---
#+end_export

이제 준비가 끝났으니 org 파일에서 Jekyll md로 익스포트하면 된다.

M-x org-export-dispatch j j

org 파일이 사이트 생성 결과물에 포함되지 않게 Jekyll _config.yml 파일 exclude 에 포함시킨다.

기존에 작성한 org 파일을 bulk로 변환

하나하나씩 언제 하냐. 디렉터리에 모든 org 파일을 찾아서 export하는 함수를 만들어서 실행했다.

(defvar my-org-bulk-export-jekyll--log-buffer-name "*My Org Bulk Jekyll Export Log*")

(defun my-org-bulk-export-jekyll ()
  (interactive)
  (let* ((posts-dir (my-org-bulk-export-jekyll-locate-posts-dir))
         (org-files (directory-files-recursively posts-dir "\\.org$"))
         (total (length org-files))
         (counter 0))

    (my-org-bulk-export-jekyll--log "Found %d .org files to export." total)

    (dolist (file org-files)
      (setq counter (1+ counter))
      (my-org-bulk-export-jekyll--log "Exporting %d/%d: %s" counter total file)
      (with-current-buffer (find-file-noselect file)
        (let ((org-export-with-broken-links 'mark))
          (org-export-to-file
              'jekyll
              (concat (file-name-sans-extension file) ".md")))))))

(defun my-org-bulk-export-jekyll-locate-posts-dir ()
  "Locate the _posts directory at the root of the current Git repository, if any."
  (let ((root (vc-git-root default-directory)))
    (when root (concat root "_posts/"))))

(defun my-org-bulk-export-jekyll--log (format-string &rest args)
  "Log a message to the dedicated export log buffer."
  (with-current-buffer (get-buffer-create my-org-bulk-export-jekyll--log-buffer-name)
    (let ((inhibit-read-only t)) ;; allow writing to read-only buffer
      (goto-char (point-max))
      (insert (apply #'format format-string args) "\n"))))

(provide 'my-org-bulk-export-jekyll)

마무리

컨버터를 내가 ownership을 가지고 수정할 마음이 없었다면 사용하면 안 된다. Jekyll 사이트 생성 파이프라인을 그대로 탈 수 있는 방법을 찾았어야 했다. 사제를 쓰니 마음에 드는 테마를 바꿀 때, 문제가 생겼다.

C-x C-s C-x C-c

링크