The Automation Begins
The Automation Begins
Having decided I should make a blog to chronicle my adventures in
Emacs, I started looking into hugo a minimal blogging framework
written in GO. It turns out that hugo
has excellent org integration,
incorporating go-org, which is the same library used by Github.
Last edit: 2024-01-20T16:42:59-09:00
Recent edits:
-
add Condensed section with one-liner versions
Condensed
As of Jan, 2024, I'm most often executing this "one-liner" version:
c:\\hugo\\hugo.exe -v -s d:/projects/bla/corwin.bru.st/ && pscp -r d:/projects/bla/corwin.bru.st/public/* dh_aw28jd@corwin.bru.st:/home/dh_aw28jd/corwin-emacs
Hopefully after using this one, which puts it on a local test server:
c:\\hugo\\hugo.exe -v --baseUrl=http://10.0.0.221/ --forceSyncStatic -s d:/projects/bla/corwin.bru.st/ && pscp -r -P 2217 d:/projects/bla/corwin.bru.st/public/* corwin@10.0.0.221:/var/www/html
Approach and Setup
As pre-work, I created the (sub) domain where this blog is hosted with
my web hosting provider's CPANEL tools Then I created a new shell user
with access only to the new site and enabled ssh access for the new
user. Finally, I installed my workstation's public ssh key into the
authorized_keys
file for new user account I use to publish the blog.
With the setup completed, I created the initial post and published it by hand, then I had supper and watched The Simpsons with the family for a while. Then I created this post and used it to published itself! 😵
Implementation
Within Emacs, this means putting my cursor with-in each of the
code-blocks in turn then pressing C-c C-c
(That's Control+C
, twice)
to execute the block the cursor is currently within ("at point").
This works because, in the org file "behind" this blog post, I warp
the code-block with special org-mode
specific mark-up that
identifies the programming language. Just as go-org
uses this
mark-up to select the right syntax highligher when rendering HTML,
org is additionally able to use system functions to invite whatever
interpretor based on the type of code the block contains.
Example:
#+BEGIN_SRC perl say "Hello, org-babel!" #+END_SRC
Windows: Fix-up for ob-sh
to use cmd.exe
I will run this first code-block only when I have restarted Emacs since I last published the blog. It sets up advice, which are a convenient way to alter how built-in Emacs functionality works.
I'm using Windows 10, so the first thing needed was a
fix for invoking cmd.exe. This SO solution is actually wrapping sh
babel processing to use cmdproxy, which can pass us back STDOUT
properly.
;;(require 'ob-sh)
(defadvice org-babel-sh-evaluate (around set-shell activate)
"Add header argument :shcmd that determines the shell to be called."
(let* ((org-babel-sh-command
(or (cdr (assoc :shcmd params)) org-babel-sh-command)))
ad-do-it))
org-babel-sh-evaluate
Render
Now we can just use hugo -D
to render the site as static content.
c:\\hugo\\hugo.exe -D -s d:/projects/bla/corwin.bru.st/
Start building sites … WARN 2024/01/20 02:32:32 Could not parse token org.token{kind:"result", lvl:0, content:"", matches:[]string{"#+RESULTS:", ""}}: Falling back to treating it as plain text. WARN 2024/01/20 02:32:32 Could not parse token org.token{kind:"result", lvl:0, content:"", matches:[]string{"#+RESULTS:", ""}}: Falling back to treating it as plain text. | EN -------------------+----- Pages | 30 Paginator pages | 2 Non-page files | 5 Static files | 1 Processed images | 0 Aliases | 5 Sitemaps | 1 Cleaned | 0 Total in 130 ms
Publish
Once the static files are rendered I use pscp to upload them to the web host.
pscp -r d:/projects/bla/corwin.bru.st/public/* dh_aw28jd@corwin.bru.st:/home/dh_aw28jd/corwin-emacs
index.html | 4 kB | 4.0 kB/s | ETA: 00:00:00 | 54% index.html | 7 kB | 7.3 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:02 | 27% index.html | 14 kB | 14.7 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:04 | 18% index.html | 22 kB | 22.1 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:08 | 10% index.html | 38 kB | 38.9 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:02 | 28% index.html | 13 kB | 13.9 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:07 | 11% index.html | 35 kB | 35.5 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:00 | 52% index.html | 7 kB | 7.6 kB/s | ETA: 00:00:00 | 100% index.html | 3 kB | 3.5 kB/s | ETA: 00:00:00 | 100% index.html | 3 kB | 3.4 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:00 | 56% index.html | 7 kB | 7.1 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:01 | 39% index.html | 10 kB | 10.1 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:00 | 94% index.html | 4 kB | 4.2 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:02 | 29% index.html | 13 kB | 13.4 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:01 | 36% index.html | 10 kB | 10.8 kB/s | ETA: 00:00:00 | 100% index.html | 3 kB | 3.4 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:03 | 21% index.html | 18 kB | 19.0 kB/s | ETA: 00:00:00 | 100% 2022-03-17-literate-emacs | 3 kB | 3.4 kB/s | ETA: 00:00:00 | 100% 2022-03-17-literate-emacs | 2 kB | 2.9 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:03 | 20% index.html | 19 kB | 19.5 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:00 | 93% index.html | 4 kB | 4.3 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:00 | 91% index.html | 4 kB | 4.4 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:00 | 51% index.html | 7 kB | 7.7 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:00 | 51% index.html | 7 kB | 7.8 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:00 | 61% index.html | 6 kB | 6.5 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:00 | 62% index.html | 6 kB | 6.4 kB/s | ETA: 00:00:00 | 100% index.html | 1 kB | 1.9 kB/s | ETA: 00:00:00 | 100% index.xml | 0 kB | 0.5 kB/s | ETA: 00:00:00 | 100% index.html | 0 kB | 0.3 kB/s | ETA: 00:00:00 | 100% style.css | 0 kB | 0.6 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:00 | 55% index.html | 7 kB | 7.2 kB/s | ETA: 00:00:00 | 100% index.xml | 4 kB | 4.0 kB/s | ETA: 00:00:02 | 28% index.xml | 13 kB | 13.9 kB/s | ETA: 00:00:00 | 100% index.html | 0 kB | 0.3 kB/s | ETA: 00:00:00 | 100% index.html | 4 kB | 4.0 kB/s | ETA: 00:00:01 | 48% index.html | 8 kB | 8.3 kB/s | ETA: 00:00:00 | 100% bard_02.txt | 4 kB | 4.0 kB/s | ETA: 00:00:02 | 29% bard_02.txt | 13 kB | 13.4 kB/s | ETA: 00:00:00 | 100% emacs-design-and-architec | 4 kB | 4.0 kB/s | ETA: 00:00:02 | 30% emacs-design-and-architec | 13 kB | 13.1 kB/s | ETA: 00:00:00 | 100% index.html | 3 kB | 3.7 kB/s | ETA: 00:00:00 | 100% index.xml | 4 kB | 4.0 kB/s | ETA: 00:00:02 | 29% index.xml | 13 kB | 13.7 kB/s | ETA: 00:00:00 | 100% package-emacs-29.sh | 4 kB | 4.0 kB/s | ETA: 00:00:00 | 88% package-emacs-29.sh | 4 kB | 4.5 kB/s | ETA: 00:00:00 | 100% index.html | 0 kB | 0.3 kB/s | ETA: 00:00:00 | 100% index.html | 3 kB | 3.4 kB/s | ETA: 00:00:00 | 100% sandwitches.org.SAVE | 4 kB | 4.0 kB/s | ETA: 00:00:00 | 54% sandwitches.org.SAVE | 7 kB | 7.4 kB/s | ETA: 00:00:00 | 100% turtle-and-snail.html | 4 kB | 4.0 kB/s | ETA: 00:00:01 | 43% turtle-and-snail.html | 9 kB | 9.2 kB/s | ETA: 00:00:00 | 100% index.html | 3 kB | 3.2 kB/s | ETA: 00:00:00 | 100% index.html | 2 kB | 2.0 kB/s | ETA: 00:00:00 | 100% index.xml | 0 kB | 0.8 kB/s | ETA: 00:00:00 | 100% index.html | 0 kB | 0.3 kB/s | ETA: 00:00:00 | 100% sitemap.xml | 3 kB | 3.3 kB/s | ETA: 00:00:00 | 100% index.html | 1 kB | 1.9 kB/s | ETA: 00:00:00 | 100% index.xml | 0 kB | 0.5 kB/s | ETA: 00:00:00 | 100% index.html | 0 kB | 0.3 kB/s | ETA: 00:00:00 | 100%
Conclusion
That's it. I'll likely clean-up the output somewhat later on. That's even more likely to happen if I need to "scrape" it for further automation later on.
UPDATE: Thanks again to sachac for the tip to use :results verbatim!
Thanks for reading!