From 065c6b0f132f97f7984e0d90dc9b3587deecd95b Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Wed, 12 Jul 2017 13:51:54 -0400 Subject: [PATCH] Add parsing of post draft state and tags from TODO state & Org tags Update example site with loads of examples. --- README.org | 12 +++++---- example-site/content-org/all-posts.org | 22 +++++++++++---- .../content/posts/draft-state-draft.md | 10 +++++++ .../{draft-state.md => draft-state-todo.md} | 5 +++- example-site/content/posts/image.md | 3 ++- .../content/posts/post-heading-slugs.md | 3 ++- example-site/content/posts/test-tags.md | 5 ++-- ox-hugo.el | 27 ++++++++++++++----- 8 files changed, 66 insertions(+), 21 deletions(-) create mode 100644 example-site/content/posts/draft-state-draft.md rename example-site/content/posts/{draft-state.md => draft-state-todo.md} (50%) diff --git a/README.org b/README.org index 30e9998..16f2cc5 100644 --- a/README.org +++ b/README.org @@ -46,19 +46,21 @@ This package might evolve into a multi-.el project. =hugo= binary in =PATH= (ii) define their =hugo= blog dir in the =defcustom= (iii) =M-x hugo=. -* TODO [2/9] +* TODO [4/9] - [X] Have =ox-hugo= be a backend derived from =ox-blackfriday= (=ox-blackfriday= needed at least for table support). - [ ] fix table horizontal rule generator, which currently adds an additional syntax-breaking space in each cell -- [ ] Parse org heading to set the hugo post title in fm +- [X] Parse org heading to set the hugo post title in fm - [-] Clean up and formalize the front matter fields - - [ ] Parse org tags to set the hugo post tags/categories in fm. + - [X] Parse org tags to set the hugo post tags/categories in fm. - [X] Use title to auto-generate file name string. - [ ] Set post date to be the same as the export date *unless* =:PUBLISHDATE:= property exists. - - [ ] Ability to set/toggle =:DRAFT: true= in property drawer. Of - course that should translate to hugo post fm. + - [X] Ability to set/toggle =:DRAFT: true= in property drawer. Of + course that should translate to hugo post fm. <2017-07-12 Wed> + Implemented an even better way.. by setting =TODO=, =DRAFT= and + =DONE= todo states. - [X] Function to re-export the whole org file to subtree-specific markdown files - [X] in image links, copy images to static dir and rewrite link target diff --git a/example-site/content-org/all-posts.org b/example-site/content-org/all-posts.org index 8ce5c0c..a3db380 100644 --- a/example-site/content-org/all-posts.org +++ b/example-site/content-org/all-posts.org @@ -126,14 +126,26 @@ This post must not be exported as it is tagged =noexport=. :EXPORT_FILE_NAME: commented-post :END: This post must not be exported as it is commented. -* COMMENT To be implemented -** TODO Draft state +* Test tags :abc:def: :PROPERTIES: -:EXPORT_FILE_NAME: draft-state +:EXPORT_FILE_NAME: test-tags +:END: +* TODO Draft state +:PROPERTIES: +:EXPORT_FILE_NAME: draft-state-todo :END: If a post has the =TODO= keyword, the =draft= front matter variable should be set to =true=. -** Test tags :abc:def: + +Idea to to mark a post or blog idea as =TODO= that you yet have to +start writing. +* DRAFT Draft state :PROPERTIES: -:EXPORT_FILE_NAME: test-tags +:EXPORT_FILE_NAME: draft-state-draft :END: +If a post has the =DRAFT= keyword too, the =draft= front matter variable +should be set to =true=. + +Idea is to mark a post as =DRAFT= that you have already started +writing, or are in the process at the moment, but it is not yet ready +to be published diff --git a/example-site/content/posts/draft-state-draft.md b/example-site/content/posts/draft-state-draft.md new file mode 100644 index 0000000..480880b --- /dev/null +++ b/example-site/content/posts/draft-state-draft.md @@ -0,0 +1,10 @@ ++++ +title = "Draft state" +date = 2017-07-12T13:46:16-04:00 +tags = [] +draft = true ++++ + +If a post has the `DRAFT` keyword too, the `draft` front matter variable should be set to `true`. + +Idea is to mark a post as `DRAFT` that you have already started writing, or are in the process at the moment, but it is not yet ready to be published diff --git a/example-site/content/posts/draft-state.md b/example-site/content/posts/draft-state-todo.md similarity index 50% rename from example-site/content/posts/draft-state.md rename to example-site/content/posts/draft-state-todo.md index bcbd313..4ad2515 100644 --- a/example-site/content/posts/draft-state.md +++ b/example-site/content/posts/draft-state-todo.md @@ -1,7 +1,10 @@ +++ title = "Draft state" -date = 2017-07-12T13:16:55-04:00 +date = 2017-07-12T13:45:57-04:00 tags = [] +draft = true +++ If a post has the `TODO` keyword, the `draft` front matter variable should be set to `true`. + +Idea to to mark a post or blog idea as `TODO` that you yet have to start writing. diff --git a/example-site/content/posts/image.md b/example-site/content/posts/image.md index 5fac2f3..5ade298 100644 --- a/example-site/content/posts/image.md +++ b/example-site/content/posts/image.md @@ -1,7 +1,8 @@ +++ title = "Image" -date = 2017-07-12T03:27:44-04:00 +date = 2017-07-12T13:46:57-04:00 tags = ["image"] +draft = false +++ **To be fixed**: At the moment, you need to place the point here and do `C-c C-e H H`. If the point is under any of the nested sub-trees in here where you do that, only that subtree gets exported. diff --git a/example-site/content/posts/post-heading-slugs.md b/example-site/content/posts/post-heading-slugs.md index 3f0003f..2cb531a 100644 --- a/example-site/content/posts/post-heading-slugs.md +++ b/example-site/content/posts/post-heading-slugs.md @@ -1,7 +1,8 @@ +++ title = "Post heading with crazy characters" -date = 2017-07-12T11:31:59-04:00 +date = 2017-07-12T13:46:33-04:00 tags = [] +draft = false +++ ## Releasing version 1.1 {#releasing-version-1-dot-1} diff --git a/example-site/content/posts/test-tags.md b/example-site/content/posts/test-tags.md index a041929..6ba8395 100644 --- a/example-site/content/posts/test-tags.md +++ b/example-site/content/posts/test-tags.md @@ -1,5 +1,6 @@ +++ title = "Test tags" -date = 2017-07-12T13:09:40-04:00 -tags = [] +date = 2017-07-12T13:48:01-04:00 +tags = ["abc", "def"] +draft = false +++ diff --git a/ox-hugo.el b/ox-hugo.el index 9721d42..5186318 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -32,6 +32,12 @@ (defvar ffap-url-regexp) ;Silence byte-compiler +(defvar org-hugo--draft-state nil + "State variable to store the \"draft\" state of the subtree to be exported.") + +(defvar org-hugo--tags-list nil + "State variable to store the tags of the subtree to be exported.") + ;;; User-Configurable Variables @@ -410,16 +416,19 @@ INFO is a plist used as a communication channel." ;; 2017-07-06T14:59:45-0400 (Note the missing colon) ;; Below simply adds that colon. (date (replace-regexp-in-string "\\([0-9]\\{2\\}\\)\\([0-9]\\{2\\}\\)\\'" "\\1:\\2" date-nocolon)) - (tags (concat - (org-export-data (plist-get info :hugo-tags) info) " " - (org-export-data (plist-get info :tags) info))) + (tags (or (org-string-nw-p (mapconcat #'identity org-hugo--tags-list " ")) + (concat + (org-export-data (plist-get info :hugo-tags) info) " " + (org-export-data (plist-get info :tags) info)))) + (draft (or org-hugo--draft-state + (org-export-data (plist-get info :hugo-draft) info))) (data `((title . ,(org-export-data (plist-get info :title) info)) (date . ,date) (description . ,(org-export-data (plist-get info :hugo-description) info)) (tags . ,tags) (categories . ,(org-export-data (plist-get info :hugo-categories) info)) (aliases . ,(org-export-data (plist-get info :hugo-aliases) info)) - (draft . ,(org-export-data (plist-get info :hugo-draft) info)) + (draft . ,draft) (publishdate . ,(org-export-data (plist-get info :hugo-publishdate) info)) (expirydate . ,(org-export-data (plist-get info :hugo-expirydate) info)) (type . ,(org-export-data (plist-get info :hugo-type) info)) @@ -606,6 +615,10 @@ Return output file's name." The next parent subtree having the \"EXPORT_FILE_NAME\" property is exported if the current subtree doesn't have that property." (interactive) + ;; Reset the state variables first + (setq org-hugo--draft-state nil) + (setq org-hugo--tags-list nil) + (save-excursion (org-back-to-heading) (let ((entry (catch 'break @@ -642,8 +655,10 @@ is exported if the current subtree doesn't have that property." "false"))) (message "[current subtree DBG] draft:%S" draft) ;; Wed Jul 12 13:10:14 EDT 2017 - kmodi - ;; FIXME: Need to now somehow pass the values of `draft' and - ;; `tags' to the INFO of the subtree. + ;; FIXME: Is there a better way than passing these + ;; values via global variables. + (setq org-hugo--draft-state draft) + (setq org-hugo--tags-list tags) (org-hugo-export-to-md nil :subtreep)))) (user-error "It is mandatory to have a subtree with EXPORT_FILE_NAME property")))))