Automating ox-hugo slugs even more

A few months ago I wrote about this blog’s “slugifying workflow” 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:

Articles from blogs I follow around the net

Trimming a Fake Object

A refactoring example. When I introduce the Fake Object testing pattern to people, a common concern is the maintenance burden of it. The point of the pattern is that you write some 'working' code only for test purposes. …

via ploeh blog November 20, 2023

Building a digital vigil for those we've lost

This post is hard to write in a lot of ways. It's more personal than most I've written. This is presumptively a tech blog, and this piece is about so much more than technology. But it's important. Making things, software or otherwise, is ultimatel…

via ntietz.com blog November 19, 2023

#122 Experimenting and Learning

Update on what happened across the GNOME project in the week from November 10 to November 17. GNOME Circle Apps and Libraries Workbench A sandbox to learn and prototype with GNOME technologies. Sonny says Workbench is a code playground and Library to learn, e…

via This Week in GNOME November 17, 2023

Generated by openring