Emacs Blogging mode take 2
emacs and hugo sitting in a tree
- tags
- emacs
- hugo
- elisp
- tabulated-list-mode
Contents
I've moved the structure of my site around so I thought I'd change up how I managed posts. Also, it was way too slow!
Lets get into it.
Set it up
|
|
List out all the files
In my content
directory I have:
articles | long posts |
howtos | walk throughs on how to do something |
labnotes | notes to my future self on how to build something |
fragments | more like short term microposts |
Most new things are org
but there are a lot of old md
files. This
finds them all up to a certain depth.
|
|
blog-mode-file-list
Parsing front matter
Rather than calling out to awk
4 times per post, lets wrap it all into
one. Also, we can reuse this for both org and md files.
|
|
blog-mode-parse-file
|
|
./index.org | [Emacs Blogging mode take 2 true 2023-06-28 emacs, hugo, elisp, tabulated-list-mode] |
Refresh the full list
|
|
blog-mode-refresh-data
Define derived-mode
This is the same as before.
|
|
Create the mode map
Here I'm defining some functions that are specific to our mode.
? | Help |
o | Open the selected file |
r | Refresh lists |
d | Only show drafts |
p | Only show published posts |
a | Show all posts |
c | Create a new post |
s | Start the hugo process |
For fun I also created a transient
popup which shows all of this.
|
|
Actions: open
I set the key to be the filename, so (find-file
(tabulated-list-get-id))
opens the file.
|
|
Actions: All/Published/Drafts
These functions filter the blog-mode-entries
variable to filter what
is displayed. I'm not sure how I feel about calling
tabulated-list-print
each time but it seems to work.
|
|
Actions: create a new post
I like my urls to be the same as the title, so the first function here normalizes the title to fit in the filesystem. I've forgotten where I copied this code from, by thank you internet.
I have two types of posts. "mini" which just means its a standalone
file, and a full post, which is in a directory. I also turn on
automatic org-babel-tangle
on save, which I set as a local org
variable.
|
|
Actions: Set date
Run this inside of a post to update the date to the current time.
|
|
Actions: Command start hugo
This is probably too particular for my machine, since I run hugo
inside of a docker container so I need to start it with a script, but
this function starts hugo if it isn't running, then waits 5 seconds to
call open
to bring it up in the browser.
|
|
Plug it in
|
|
References
- https://pagefault.se/post/lets-build-docker-mode-part-1/
- https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Name-Components.html#File-Name-Components
- http://lgmoneda.github.io/2017/03/15/elisp-summary.html#loops
- http://ergoemacs.org/emacs/elisp_vector.html
- https://stackoverflow.com/questions/2234860/lisp-filter-out-results-from-list-not-matching-predicate
- https://vallyscode.github.io/posts/tabulated-list-mode/
Previously
Next