Closed max-arnold closed 2 years ago
I wrote an initial version, feel free to improve it:
(defun hugo-slugify (start end)
(interactive "r")
(if (use-region-p)
(let ((regionp (buffer-substring start end)))
(save-excursion
(delete-region start end)
(insert
(replace-regexp-in-string
"[^a-z0-9-]" ""
(replace-regexp-in-string
"\s+" "-"
(downcase regionp)
)))))))
Hi @max-arnold . Thank you for comment. I've implemented easy-hugo-slugify at https://github.com/masasam/emacs-easy-hugo/commit/baead14d7f2fa86e108269932a94bf376de9c2e5. I hope you find it useful.
Sometimes it is necessary to convert a title to slug - it could be a blog post title, or a section title. It would be nice to have a helper function in easy-hugo that converts selected text to a slug in the same way as hugo (goldmark?) does: https://discourse.gohugo.io/t/difference-in-auto-generated-heading-anchor-names-between-previous-versions-and-v0-60-0-or-higher/22076