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

Export happens even when EXPORT_FILE_NAME is empty #211

Closed
takaxp opened this issue Sep 26, 2018 · 8 comments
Closed

Export happens even when EXPORT_FILE_NAME is empty #211

takaxp opened this issue Sep 26, 2018 · 8 comments
Labels

Comments

@takaxp
Copy link
Contributor

takaxp commented Sep 26, 2018

Hi!

When I use the latest ox-hugo with ox-hugo-auto-export and auto-save-buffers.el, unexpected files were exported during writing a new post in an org file.

For example, my org file is organized as:

* 2018
:PROPERTIES:
:EXPORT_HUGO_SECTION: 2018
:END:
** DONE post1
   CLOSED: [2018-09-15 Sat 00:35]
:PROPERTIES:
:EXPORT_FILE_NAME: 0915-pasta-puttanesca
:EXPORT_HUGO_TAGS: "pasta" "tomato"
:CREATED:  [2018-09-25 Tue 00:35]
:END:

Then I create a new post via org-capture, the file will be the following and automatically saved by auto-save-buffer.el.

* 2018
:PROPERTIES:
:EXPORT_HUGO_SECTION: 2018
:END:
** DONE post1
   CLOSED: [2018-09-15 Sat 00:35]
:PROPERTIES:
:EXPORT_FILE_NAME: 0915-pasta-puttanesca
:EXPORT_HUGO_TAGS: "pasta" "tomato"
:CREATED:  [2018-09-25 Tue 00:35]
:END:
** TODO post2
:PROPERTIES:
:EXPORT_FILE_NAME:
:EXPORT_HUGO_TAGS: 
:CREATED:  [2018-09-26 Wed 15:45]
:END:

In this case, the second post will be immediately exported as 2018/.md because org-hugo--parse-draft-state always return t. Moreover, 2018/a-new-.md could be exported during thinking the blog title because auto-save-buffers.el will be activated after going by an idle time, e.g. 1.5[s].

My proposal is refining the behavior of org-hugo--parse-draft-state. The function should return t only when the org state is DRAFT or specifying HUGO_DRAFT in the post.

Something like this:

(if (member (org-entry-get (point) "TODO") org-done-keywords)
    nil
  (progn
    (if (string= "DRAFT" (org-entry-get (point) "TODO"))
        t
      nil)))
@kaushalmodi
Copy link
Owner

In this case, the second post will be immediately exported as 2018/.md because org-hugo--parse-draft-state always return t.

That is a bug, but not what you think :)

The posts are always exported. If the state is DONE, they are exported with draft = true, else they are exported with draft = false.

The bug is that export is happening even when EXPORT_FILE_NAME is empty! It never makes sense to have an export as valid when that key is present.

Thanks for catching this, and also providing a test. I'll fix it.

@kaushalmodi kaushalmodi changed the title DRAFT state and exporting Don't export if EXPORT_FILE_NAME is empty Sep 26, 2018
@kaushalmodi kaushalmodi changed the title Don't export if EXPORT_FILE_NAME is empty Export happens even when EXPORT_FILE_NAME is empty Sep 26, 2018
@kaushalmodi
Copy link
Owner

Then I create a new post via org-capture, the file will be the following and automatically saved by auto-save-buffer.el.

Also, you will not face this bug if you derive your Org capture template from the ox-hugo documentation. I use org-hugo-slug to derive the export file name from the title (and I always type the title at the capture prompt).

@takaxp
Copy link
Contributor Author

takaxp commented Sep 26, 2018

Yep. But I didn't follow the template that you mentioned, and sometime I decide the title after C-c C-c or C-u C-c C-c for org-capture :)
So, I'll customize my config for auto-save-buffers.el to prevent auto saving if the cursor on the same line of EXPORT_FILE_NAME :)

@kaushalmodi
Copy link
Owner

kaushalmodi commented Sep 26, 2018

Unrelated question: I am curious why you are using EXPORT_HUGO_TAGS instead of the normal Org tags.

If you use Org tags, you can "collect" tags from the parent hierarchy too.

* Cooking posts :cooking:
** Pasta recipes :pasta:
*** Pasta Puttanesca :tomato:
:PROPERTIES: 
:EXPORT_FILE_NAME: 0915-pasta-puttanesca 
:END:
This post has all 3 tags: cooking, pasta, tomato

@takaxp
Copy link
Contributor Author

takaxp commented Sep 26, 2018

That's interesting. But I want to keep my all posts in the second level of org headings. In order to that, if I put all tags to the headings, the headings will be messed up. Since I want to keep the heading line clean and simple, I usually put only one category to the heading line like @cooking and put multiple tags in EXPORT_HUGO_TAGS :)

@kaushalmodi
Copy link
Owner

kaushalmodi commented Sep 26, 2018

sometime I decide the title after C-c C-c or C-u C-c C-c for org-capture

Hmm, that first C-c C-c after capture shouldn't have caused the export in any case. I'll investigate.

@takaxp
Copy link
Contributor Author

takaxp commented Sep 26, 2018

Here is a demo.

untitled

@kaushalmodi
Copy link
Owner

kaushalmodi commented Sep 26, 2018

@takaxp OK, after that last commit, now at least the ".md" files won't export. If you attempt to export, you will get:

FILENAME.org: Point is not in a valid Hugo post subtree; move to one and try again

So that resolved one part of the problem.

Let's resolve part 2 of the problem (why C-c C-c attempts to export in Org Capture) in #212.

Thanks for reporting such issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants