Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set custom export directory (and flycheck cleanups) #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 51 additions & 17 deletions ox-jekyll-md.el
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
;;; ox-jekyll-md.el --- Export Jekyll on Markdown articles using org-mode. -*- lexical-binding: t; -*-
;;; ox-jekyll-md.el --- Export Jekyll on Markdown articles using org-mode -*- lexical-binding: t; -*-

;; Copyright (C) 2018 Elsa Gonsiorowski

;; Author: Elsa Gonsiorowski <[email protected]>
;; Author: Yoshinari Nomura <[email protected]>
;; Author: Justin Gordon <[email protected]>
;; Keywords: org, jekyll
;; Homepage: https://github.com/gonsie/ox-jekyll-md
;; Package-Requires: ((emacs "26.1"))
;; Keywords: org, jekyll, blog, convenience
;; Version: 0.1

;; This is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -41,7 +43,7 @@

;;; User Configurable Variables

(defgroup org-export-jekyll-md nil
(defgroup org-jekyll-md nil
"Options for exporting Org mode files to jekyll MD."
:tag "Org Jekyll MD"
:group 'org-export
Expand All @@ -64,13 +66,13 @@ keywords: Octopress
description: Instructions on Upgrading Octopress
---
#+END_EXPORT HTML"
:group 'org-export-jekyll
:group 'org-jekyll-md
:type 'boolean)


(defcustom org-jekyll-md-layout "post"
"Default layout used in Jekyll article."
:group 'org-export-jekyll
:group 'org-jekyll-md
:type 'string)

(defcustom org-jekyll-md-categories ""
Expand All @@ -80,7 +82,7 @@ description: Instructions on Upgrading Octopress

(defcustom org-jekyll-md-tags ""
"Default space-separated tags in Jekyll article."
:group 'org-export-jekyll
:group 'org-jekyll-md
:type 'string)

(defcustom org-jekyll-md-use-src-plugin t
Expand All @@ -96,12 +98,32 @@ makes:
{% highlight ruby %}
puts \"Hello world\"
{% endhighlight %}"
:group 'org-export-jekyll-use-src-plugin
:group 'org-jekyll-md-use-src-plugin
:type 'boolean)

(defcustom org-jekyll-md-use-todays-date t
"If t, org-jekyll-md exporter will prepend the filename with today's date."
:group 'org-export-jekyll
:group 'org-jekyll-md
:type 'boolean)

(defcustom org-jekyll-md-project-directory default-directory
"Directory to save exported articles to.
\nDefaults to `default-directory' (i.e. current directory). See
`org-jekyll-md-use-prompt-for-directory' if you
want to choose a directory on saving."
:group 'org-jekyll-md
:type 'string)

(defcustom org-jekyll-md-prompt-for-directory nil
"Non-nil means prompt for a directory to save in.
\nStart at `org-jekyll-md-project-directory'. Nil means
use `org-jekyll-md-project-directory' with no prompt."
:group 'org-jekyll-md
:type 'boolean)

(defcustom org-jekyll-find-file-on-export nil
"Non-nil means open the Markdown file after exporting."
:group 'org-jekyll-md
:type 'boolean)

;;; Define Back-End
Expand Down Expand Up @@ -176,9 +198,10 @@ Assume BACKEND is `jekyll'."
(defun org-jekyll-md-src-block (src-block contents info)
"Optionally transcode SRC-BLOCK element into jekyll code template format.

Use `highlight` / `endhighlight` if `org-jekyll-md-use-src-plugin` is t. Otherwise,
perform `org-md-src-block`. CONTENTS holds the contents of the item. INFO is a
plist used as a communication channel."
Use `highlight` / `endhighlight` if
`org-jekyll-md-use-src-plugin' is t. Otherwise, perform
`org-md-src-block'. CONTENTS holds the contents of the item. INFO
is a plist used as a communication channel."
(if org-jekyll-md-use-src-plugin
(let ((language (org-element-property :language src-block))
(value (org-remove-indentation
Expand Down Expand Up @@ -217,8 +240,7 @@ holding export options."
(concat
(org-jekyll-md--yaml-front-matter info)
contents)
contents
))
contents))

(defun org-jekyll-md-inner-template (contents info)
"Return body of document string after MD conversion.
Expand Down Expand Up @@ -303,11 +325,23 @@ holding export options."

;;;###autoload
(defun org-jekyll-md-export-to-md (&optional async subtreep visible-only)
"Export current buffer to a Markdown file adding some YAML front matter."
"Export current buffer to a Markdown file adding some YAML front matter.
\nThe file is saved to `org-jekyll-md-project-directory'.
If `org-export-md-prompt-for-directory' is non-nil, prompt
for a directory to save to."
(interactive)
(let ((outfile (concat (org-jekyll-md-filename-date)
(org-export-output-file-name ".md" subtreep))))
(org-export-to-file 'jekyll outfile async subtreep visible-only)))
(let* ((pub-dir (if org-jekyll-md-prompt-for-directory
(read-directory-name "Save to: "
org-jekyll-md-project-directory
nil
t)
org-jekyll-md-project-directory))
(outfile (concat pub-dir
(org-jekyll-md-filename-date)
(org-export-output-file-name ".md" subtreep))))
(org-export-to-file 'jekyll outfile async subtreep visible-only)
(when org-jekyll-md-find-file-on-export
(find-file outfile))))

;;;###autoload
(defun org-jekyll-md-publish-to-md (plist filename pub-dir)
Expand Down