But will it even work?
Oh right I need to :UpdateRemotePlugins
first.
Test [PASSED]
It worked!
What did I just do?
I used a remote plugin in Neovim to transform my reStructuredText into an HTML source document, simplifying Hugo’s site-building duties.
I won’t make you wait around for a proper post. Hugo lets you use reStructuredText. But Hugo’s way is slow and hard to customize. Not their fault. reStructuredText is not their focus.
Still — why not format it ahead of time?
Answer
Because it took a lot of work to figure this out? And most folks are perfectly happy with Markdown? And bloggers who prefer reStructuredText are probably using Pelican or Nikola?
Shush, me.
The Implementation
Start with content/whatever/index.rst.txt
.
Make sure Hugo won’t track rst.txt
files by explicitly adding an item the ignoreFiles
config setting.
This way hugo server --navigateToChanged
behaves how we expect.
I tried setting ignoreFiles = ['\.rst$']
but as far as I could tell, Hugo ignored my request to ignore the file. Looks like I’m sticking with .rst.txt
for now.
With the code down below in my Neovim python3 — that’s python3 not python — rplugin folder, and remote plugins updated, I write index.rst.txt
to disk.
The remote plugin transforms it to HTML, copying my YAML frontmatter as is. So what Hugo sees is updated HTML with frontmatter, and builds that into the site templates nice and quick.
The Code
Lord knows this code ain’t perfect. This post is its main test. Who knows what bugs and improvements will come later?
NOTE
You will, if you skim the Updates at the end.
If you grab a copy for your own nefarious plans — a similar template could get you fast Asciidoctor transforms as well — just remember a couple things:
-
make sure the Python you’re using has the libraries needed; I listed my choices below
-
put it in the right folder;
rplugin/python
is for Python 2;rplugin/python3
is for Python 3 -
run
:UpdateRemotePlugins
and restart Neovim when you make changes to the plugin file
Libraries Used
- Docutils of course, for transforming the reStructuredText
- Docutils takes advantage of the fact that I have Pygments installed, for syntax highlighting
- Python Frontmatter gives me a consistent tool for handling post frontmatter and content
- pynvim is the bit that hooks it all into Neovim
Backlinks
Got a comment? A question? More of a comment than a question?
Talk to me about this page on: mastodon
Added to vault 2024-01-15. Updated on 2024-02-01