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

Feature request: title to slug #64

Closed
max-arnold opened this issue Oct 17, 2021 · 2 comments
Closed

Feature request: title to slug #64

max-arnold opened this issue Oct 17, 2021 · 2 comments

Comments

@max-arnold
Copy link

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

@max-arnold
Copy link
Author

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)
             )))))))

@masasam
Copy link
Owner

masasam commented Oct 17, 2021

Hi @max-arnold .
Thank you for comment.
I've implemented easy-hugo-slugify at baead14.
I hope you find it useful.

@masasam masasam closed this as completed Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants