Elisp for Hugo

Now that I am writing all my blog posts using orgmode, I wanted a way to create the file I need for a new post automatically. I couldn't find quite what I wanted, so here is my attempt and writing some elisp to make it happen.

  (defun s-dashed-words (words)
     (replace-regexp-in-string "[^a-z0-9]+" "-" words)))

  (defun ps/new-hugo-post (title &optional)
    "Create and visit a new draft blog post for the prompted TITLE.

     The file for the blog post conforms to the path schema of posts
    (interactive "sTitle: ")

    (let* ((post-dir (concat ps/data "Code/Websites-source/petersmith/content/blog/"
                               (format-time-string "%Y%m%d-") (s-dashed-words title) "/"))
           (post-fpath (concat post-dir ""))
           (post-slug (s-dashed-words title))
           (post-date (format-time-string "%+4Y-%m-%dT%H:%M:%S%:z")))

      (make-directory post-dir t)

      (write-region (concat
                 "\n#+title: " title
                 "\n#+date: " post-date
                 "\n#+lastmod: " post-date
                 "\n#+categories[]: Tech"
                 "\n#+tags[]: "
                 "\n#+slug: " post-slug
                 "\n#+draft: False"
                nil (expand-file-name post-fpath) nil nil nil t)

  (find-file (expand-file-name post-fpath))))

A good chunk of the code came from a post by Jeremy Friesen at Take on Rules. Thanks! (And that reminds me, I still have to get webmentions working).

I modified Jeremy's code a bit to allow for the fact that I use Hugo's page bundles.

If you webmention this page, please let me know the URL of your page.

BTW: Your webmention won't show up until I next "build" my site.

Show all the shares aka