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

Already on GitHub? Sign in to your account

Delete old Markdown file when editing the EXPORT_FILE_NAME #34

Open
kaushalmodi opened this Issue Jul 13, 2017 · 3 comments

Comments

2 participants
Owner

kaushalmodi commented Jul 13, 2017

If the EXPORT_FILE_NAME was "a" and then we changed that to "b", we will end up with both a.md and b.md.

Need to figure out how to delete the old file when new file is created.

Contributor

punchagan commented Jul 24, 2017

One idea could be to maintain a "database" of the posts that have been exported from ox-hugo. Posts could be given a custom ID on export, and map that to some post metadata in the DB, including EXPORT_FILE_NAME.

If we go with this idea, we could also store a hash of the subtree/post contents, to detect changes to any of the posts, and let "export all subtrees" identify and export only the changed ones.

Owner

kaushalmodi commented Jul 24, 2017

Would you like to implement this? Also I don't know what the performance impact would be for big blogs if the hash has to be calculated for dozens/hundreds of posts with, let's say, 2000 words each, for each export. Poor man solution would be to rely on git diff to see which posts changed, and export just those :) Git diff also helps catch any unintended text change in older posts.

About the implementation specific to deleting old Markdown files, here's my thought: Each time a post is exported, this one property should be saved to the subtree: EXPORTED_FILE_NAME.

So..

Before first export

* My Post
:PROPERTIES:
:EXPORT_HUGO_SECTION: posts
:EXPORT_FILE_NAME: my-post
:END:

After first export

* My Post
:PROPERTIES:
:EXPORT_HUGO_SECTION: posts
:EXPORT_FILE_NAME: my-post
:EXPORTED_FILE_NAME: posts/my-post
:END:

(assuming the extension to be always .md)


After EXPORT_FILE_NAME rename (and even section change!) -- Before export

* My Article
:PROPERTIES:
:EXPORT_HUGO_SECTION: articles
:EXPORT_FILE_NAME: my-article
:EXPORTED_FILE_NAME: posts/my-post
:END:

Here as (concat <EXPORT_HUGO_SECTION> "/" <EXPORT_FILE_NAME>) does not match with <EXPORTED_FILE_NAME>, the renaming/file moving will happen.

After EXPORT_FILE_NAME rename (and even section change!) -- After export

* My Article
:PROPERTIES:
:EXPORT_HUGO_SECTION: articles
:EXPORT_FILE_NAME: my-article
:EXPORTED_FILE_NAME: articles/my-article
:END:

.. and after the export, the <EXPORTED_FILE_NAME> will be once again updated.

Contributor

punchagan commented Jul 24, 2017

Would you like to implement this? Also I don't know what the performance impact would be for big blogs if the hash has to be calculated for dozens/hundreds of posts with, let's say, 2000 words each, for each export. Poor man solution would be to rely on git diff to see which posts changed, and export just those :) Git diff also helps catch any unintended text change in older posts.

I would like to try using the after save hook that you have provided with ox-hugo for a while, and see how it feels, before trying to implement this. Piggybacking on git diff is a nice idea!

Each time a post is exported, this one property should be saved to the subtree: EXPORTED_FILE_NAME.

This seems like a reasonable way to go about it. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment