Last active
May 20, 2017 21:37
-
-
Save shoover/d75a58074be9894bfc54 to your computer and use it in GitHub Desktop.
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
# Exports all .org files in argument dirs as HTML. | |
# | |
# Usage: rake -f export-org-dirs.rb DIR+ [sync_mobile] | |
# | |
# sync_mobile (if not a dir) will fire off org-mobile-push and -pull if the | |
# mobile index is out of date wrt org files in dirs. This happens in the | |
# server so it saves your work and updates locally instead of behind your back | |
# and demanding a revert. It is advised to set this up to run only when the | |
# computer is idle so it doesn't go crazy while you're editing. | |
# | |
# Export could be done easily with the org project system if you didn't mind | |
# storing and loading the elisp somewhere and invoking emacs every time the | |
# script is run. | |
# | |
# (defun publish-org-dir (dir) | |
# (let* ((dir-exp (expand-file-name dir)) | |
# (org-publish-project-alist | |
# `(("PROJECT" | |
# :base-directory ,dir-exp | |
# :publishing-directory ,(concat dir-exp "/html"))))) | |
# (org-publish-project (assoc "PROJECT" org-publish-project-alist)))) | |
INDEX = File.join(ENV['HOME'], 'dropbox', 'apps', 'mobileorg', 'index.org') | |
ARGV.each do |dir| | |
next unless Dir.exist? dir | |
dir_exp = File.expand_path(dir) # Correct slashes | |
org = FileList["#{dir_exp}/*.org"] | |
file INDEX => org | |
html = org.ext('html') | |
task dir => html | |
end | |
rule '.html' => ['.org'] do |t| | |
load_org = " | |
(progn | |
(require 'package) | |
(package-initialize) | |
(require 'org) | |
(message \\\"Using org-version %s\\\" org-version) | |
(setq make-backup-files nil))".delete("\n") | |
cmd = "emacs --batch --eval \"#{load_org}\" " + | |
"--visit \"#{t.source}\" --funcall org-html-export-to-html" | |
puts cmd | |
system cmd | |
end | |
file INDEX do | |
cmd = "emacsclient --eval \"(org-mobile-push)\" --eval \"(org-mobile-pull)\"" | |
system cmd | |
end | |
task :sync_mobile => INDEX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment