Skip to content

Commit

Permalink
Generate README, CONTRIBUTE, Wiki pages from ox-hugo-manual.org
Browse files Browse the repository at this point in the history
See ox-hugo-export-gh-doc function in doc/export-gh-doc.el
  • Loading branch information
kaushalmodi committed Aug 8, 2017
1 parent 0dd01f2 commit 60daaee
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "doc/ox-hugo.wiki"]
path = doc/ox-hugo.wiki
url = https://github.com/kaushalmodi/ox-hugo.wiki.git
3 changes: 2 additions & 1 deletion CONTRIBUTING.org
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#+TITLE: Contributing Guide
#+AUTHOR: Kaushal Modi
-----

NOTE TO FUTURE CONTRIBUTORS: I plan to merge this package into Org
Expand All @@ -13,7 +15,6 @@ As a bonus, once you have assigned your copyright to FSF, doors open up
for your contributions to Emacs too!

-----

* Debug
If the =ox-hugo= exports do not work as expected, or if you get an
error backtrace,
Expand Down
61 changes: 33 additions & 28 deletions README.org
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#+TITLE: Ox-Hugo: A carefully crafted Org exporter back-end that enables writing Hugo posts in Org
#+AUTHOR: Kaushal Modi
-----

NOTE TO FUTURE CONTRIBUTORS: I plan to merge this package into Org
Expand Down Expand Up @@ -25,27 +27,15 @@ Here is the blogging flow when using this package:
- One post per Org file (/works but you won't be able to leverage
Org-specific benefits like tag and property inheritance, use of
TODO states to translate to post =draft= state, etc./)
- Export only the *current* post Org subtree
- Export all post subtrees
- Export only the *current* post Org subtree, or export all post
subtrees.
- Set up =org-capture= (see below) to quickly start writing new posts.
- Use =after-save-hook= to export current post subtree to Markdown on
each save.

This project consists of =ox-blackfriday.el= too. It is a derivation
of [[https://github.com/larstvei/ox-gfm][=ox-gfm=]] with support added for Blackfriday Markdown tables and
few other tweaks. =ox-hugo= backend extends from this.

There is a plan to create a =hugo.el= that would do things like:
- New post creation using =org-capture= (port code from [[https://github.com/kaushalmodi/.emacs.d/blob/master/setup-files/setup-hugo.el][here]]).
- Interactive functions to toggle /draft/ state,
add/remove/increment/decrement /publishdate/ property.
- Option to use template =config.toml= and some default hugo theme. So
all a new user would need to do is to (i) have the =hugo= [[https://github.com/gohugoio/hugo/releases][binary]] in
=PATH= (ii) define their =hugo= blog dir in the =defcustom= (iii)
=M-x hugo=.
- Set separate faces for titles based on /draft/ state and
/futureness/.

many other tweaks. =ox-hugo= backend extends from this.
* Formatting
Below table shows the translation of Org markup to Markdown markup in
the exported =.md= files.
Expand Down Expand Up @@ -125,32 +115,37 @@ translate to Hugo front matter:
one can take advantage of Org subtree filtering and searching
functions.
- (and much more..)

* Implicit setting of Hugo front matter variables in Org
* Translation of Org meta-data to Hugo front matter
Many Hugo front matter variables get set implicitly using the
meta-data parsed from the posts in Org.
|---------------------------+----------------------------+--------------------------------------|
| Hugo front matter (TOML) | Org | Org description |
|---------------------------+----------------------------+--------------------------------------|
| =title = "foo"​= | =* foo= | Heading |
| =date = 2017-07-24= | =:EXPORT_DATE: 2017-07-24= | Subtree property |
| =tags = ["abc", "def"]= | =* foo :abc:def:= | Heading tags |
| =categories = ["x", "y"]= | =* foo :@x:@y:= | Heading tags with =@= prefix |
| =tags = ["abc", "def"]= | =* foo :abc:def:= | Heading tags |
| =categories = ["x", "y"]= | =* foo :@x:@y:= | Heading tags with =@= prefix |
| =draft = true= | =* TODO foo= | Heading set to TODO (or DRAFT) |
| =draft = false= | =* foo= | Heading *not* set to TODO (or DRAFT) |
|---------------------------+----------------------------+--------------------------------------|
* Try =ox-hugo=
* How to try =ox-hugo=?
1. Clone this repo.
2. Run =hugo server --buildDrafts --buildFuture --navigateToChanged= in
=example-site/= directory.
2. =cd= to the =example-site/= directory and do:
#+BEGIN_EXAMPLE
hugo server -D --navigateToChanged
#+END_EXAMPLE
- =--navigateToChanged= requires Hugo 0.25+.
3. Above command will mention the localhost where the site is
served.Open that in your browser.
served. Open that in your browser.
4. In emacs, =(require 'ox-hugo)= or evaluate the =ox-hugo.el= from the
cloned repo.
5. Open the [[https://raw.githubusercontent.com/kaushalmodi/ox-hugo/master/example-site/content-org/all-posts.org][=all-posts.org=]] file.
6. =C-c C-e H A= -- Export *all* subtrees in the file to Markdown files.
7. In few seconds, 40+ test posts will get created, with the hugo server
preview in the browser zapping through each new created post (needs
that new Hugo 0.25 feature).
6. =C-c C-e H A= -- That will export *all* subtrees in the file to
Markdown files.
7. In few seconds, dozens of test posts will get created, with the
=hugo server= aided preview in the browser zapping through each new
created post (needs that new feature =--navigateToChanged=
introduced in Hugo 0.25).
* Debug
If the =ox-hugo= exports do not work as expected, or if you get an
error backtrace,
Expand All @@ -162,7 +157,17 @@ error backtrace,
- Paste the Markdown contents in the GitHub issue.
- You can still hit the /Preview/ tab of the Issue before
submitting it.

* Future Plans
There is a plan to create a =hugo.el= that would do things like:
- New post creation using =org-capture= (port code from [[https://github.com/kaushalmodi/.emacs.d/blob/master/setup-files/setup-hugo.el][here]]).
- Interactive functions to toggle /draft/ state,
add/remove/increment/decrement /publishdate/ property.
- Option to use template =config.toml= and some default hugo theme. So
all a new user would need to do is to (i) have the =hugo= [[https://github.com/gohugoio/hugo/releases][binary]] in
=PATH= (ii) define their =hugo= blog dir in the =defcustom= (iii)
=M-x hugo=.
- Set separate faces for titles based on /draft/ state and
/futureness/.
* Thanks
- Matt Price (@titaniumbones)
- [[http://www.holgerschurig.de/en/emacs-blog-from-org-to-hugo/][holgerschurig.de]]
Expand Down
45 changes: 45 additions & 0 deletions doc/export-gh-doc.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
;; Time-stamp: <2017-08-08 12:20:38 kmodi>

;; Helper function to export Org documentation to GitHub repo Wiki pages

(defun ox-hugo-export-gh-doc ()
"Export `ox-hugo' Org documentation to documentation on GitHub repo."
(interactive)
(let* ((ox-hugo-root-dir (cdr (project-current))) ;Requires emacs 25.1
(ox-hugo-doc-dir (concat ox-hugo-root-dir "doc/"))
(ox-hugo-org-file (expand-file-name "ox-hugo-manual.org" ox-hugo-doc-dir))
;; cd doc/
;; git clone https://github.com/kaushalmodi/ox-hugo.wiki.git
(ox-hugo-wiki-dir (concat ox-hugo-doc-dir "ox-hugo.wiki/"))
(org-src-preserve-indentation t) ;Preserve the leading whitespace in src blocks
(org-id-track-globally nil) ;Prevent "Could not read org-id-values .." error
(org-export-with-sub-superscripts '{})
(org-export-with-smart-quotes t)
(org-export-headline-levels 4)
(org-src-fontify-natively t))
(if (file-exists-p ox-hugo-wiki-dir)
(let ((subtree-tags-to-export '("readme" "contributing" "wiki"))
;; If a subtree matches a tag, do not try to export further
;; subtrees separately that could be under that.
(org-use-tag-inheritance nil)
(org-export-time-stamp-file nil) ;Do not print "Created <timestamp>" in exported files
(org-export-with-toc nil) ;Do not export TOC
(org-export-with-tags nil)) ;Do not print tag names in exported files
(dolist (tag subtree-tags-to-export)
(let* ((exported-file-list (org-map-entries '(org-org-export-to-org nil :subtreep) tag)))
;; Move files to their correct directories
(cond
((or (string= "readme" tag)
(string= "contributing" tag))
(dolist (exported-file exported-file-list)
(rename-file (expand-file-name exported-file ox-hugo-doc-dir)
(expand-file-name exported-file ox-hugo-root-dir)
:ok-if-already-exists)))
((string= "wiki" tag)
(dolist (exported-file exported-file-list)
(rename-file (expand-file-name exported-file ox-hugo-doc-dir)
(expand-file-name exported-file ox-hugo-wiki-dir)
:ok-if-already-exists)))))))
(user-error (concat "ox-hugo.wiki dir does not exist. "
"You need to `cd doc/' and "
"`git clone https://github.com/kaushalmodi/ox-hugo.wiki.git'")))))
Loading

0 comments on commit 60daaee

Please sign in to comment.