Programming: More Emacs for Hugo Scripting

Converting Youtube WordPress Links to iframe Embeds

Yesterday’s DIY involved converting posts from dreamwidth to hugo (actually jekyl). Most of the heavy lifting was done by Thomas Frössm’s exitwp. Once everything was exported into jekyll-flavored markdown, one minor gap was youtube embeds. First, a skeleton for wrapping the iframe around a youtube movie code.

Code on pastebin to get around wordpress sanitation

Then, a function to do it automatically.

(defun kjs/youtube-convert ()
  (interactive)
  (re-search-forward "^http.://.*youtube.*v=")
  (let (p1 p2 myLine code)
    (setq p1 (line-beginning-position) )
    (setq p2 (line-end-position) )
    (setq myLine (buffer-substring-no-properties p1 p2))
    (setq code (replace-regexp-in-string ".*v=" "" myLine))
    (forward-line 2)
    (kjs/youtube-embed)
    (insert code)
    (beginning-of-line)))

Back/Next Page Navigation

How to do back/next pagination came from a snippit by Justin Dunham.

Create a Tag List on a Post

How to create a tag list on a post. Here is the template code in /layouts/_defaults/single.html:

More pastebin

And the css:

.tags ul {
    padding-left: .5rem;
}

.tags {
    display: inline;
    font-size: 70%;
    background-color: #ddd;
}

.tags li {
    display: inline;
}

Archive Page by Date

Figuring out exactly how to get an archive page working took a lot of frustrating searches. I finally found the right template at: /layouts/_defaults/list.html:

More pastebin (see second listing)

Downloading Images from WordPress

exitwp doesn’t grab images. So use grep to get all of the image urls and curl to download them into the images folder.

egrep -oh "https://[^)]+files.wordpress.com/[^)]+.jpg" ~/Dropbox/hugo-blog-test/content/post/*.markdown | xargs -n 1 curl -O

Bulk Edit Files to Point to the Image Folder

Run in the posts folder.

perl -p -i.bak -e 's/https:\/\/[^)]+files.wordpress.com\/[^)]+\//\/images\//' *.markdown 
Advertisements