Automating ox-hugo slugs even more

A few months ago I wrote about this blog's ["slugifying workflow"]({{< relref "slugifying-this-blog-s-headings" >}}) and how it works. However, I'll be honest, it's still quite shameful how manual the whole thing is. I mean, it still requires will to manually add properties and paste the value there. It should be done automatically for you if you consider that this is inside GNU Emacs!

I wish I could write a whole blog post about the adventure of finding out the pieces I had to put together, but it was way easier than I expected.

(defun gluer/slugify-hugo-heading ()
  "Gets the current heading title, slugifies it and sets the
`EXPORT_FILE_NAME` and `EXPORT_HUGO_SLUG` properties with its
value."
  (interactive)
  (let* ((title (org-entry-get nil "ITEM"))
	 (slug (org-hugo-slug title)))
    (org-entry-put nil "EXPORT_FILE_NAME" slug)
    (org-entry-put nil "EXPORT_HUGO_SLUG" slug)
    (message "Successfully added '%s' slug." slug)))

In order to run this, you just need to press M-x gluer/slugify-hugo-heading at the level you want to add the properties (usually the top heading of your post).

For instance, this same article you are reading looks like this:

** Automating ox-hugo slugs even more                                :emacs:
:PROPERTIES:
:EXPORT_FILE_NAME: automating-ox-hugo-slugs-even-more
:EXPORT_HUGO_SLUG: automating-ox-hugo-slugs-even-more
:END: