Status: ON-GOING
If you meant to check my digital garden, click here: Wiki.
This page talks about the current implementation of said digital garden.
Having a second brain is getting more popular. In it’s simplest form, it’s a bunch of personal notes on different topics compiled over a period of time. When these notes are linked to one another so that they might form new ideas, then their sum becomes a knowledge base—a low-tech brain if you will—that one can use to help with Thinking.
go to top ⤒This write-up assumes the following that the reader:
The out-of-the-box .wiki syntax of Vimwiki is a derivative of
Markdown, but not the variant that’s widely adopted. So, for a cohesive
experience, I included the following snippet init.vim it so I can use the
Markdown syntax, that is, text files with .md extension:
let g:vimwiki_list = [{'path': '~/path/to/vimwiki/',
\ 'syntax': 'markdown', 'ext': '.md'}]
With this I can now write notes using .md and NOT .wiki, which is important because Hugo only works with the former.
I made a separate section in Hugo’s site’s folder structure, under
content, called wiki, into which I’ll copy my PKM files. (For more
info on this, Hugo’s Quick Start is a helpful
guide.)
mkdir content/wiki/
go to top ⤒
Ensure that there is a wiki folder under
layouts/:
mkdir layouts/wiki/
I populate this folder with single.html and list.html files; the former is
a template for how each page in the wiki would look like, and the latter
is for the list of all the notes.
The following are the stripped down version for single.html:
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ .Content }}
{{ end }}
And now, the list.html:
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ range .Pages.ByLastmod }}
<a href="{{ .RelPermalink }}">{{ .Title }}</a><br>
{{ end }}
{{ end }}
go to top ⤒
I created an _index.md file placed under the content/wiki/ section, and this just contains the title of that page, like so:
---
title: "Digital Garden 🌱"
---
Meanwhile, recall VimWiki also has its own index.md (originally
index.wiki out of the box). When copying the offline PKM files into
content/wiki/ section, we don’t need to copy this particular index
file to not cause any weird issues.
To be clear, I don’t have my PKM within this Hugo’s site directory. I am keeping it in a separate folder, to have compartmentalization. This friction is non-issue for now as will be apparent in the next few commands.
go to top ⤒To migrate, I run a few commands in my terminal:
cp -rv /path/to/offline-wiki/*.md /home/user/site-directory/content/wiki/
rm /home/user/site-directory/content/wiki/index.md
cp line just copies all .md files to the wiki section of this
site.rm line deletes the index file of the offline wikiPRO TIP: To make this easier, I have included these lines in a Makefile that builds and publishes my website. When I run make build in my terminal, my
blog update now includes the latest changes from my wiki. (Note: making
a Makefile is outside the scope of this post.)
For this to work, each note must be Hugo-ready. Writing the notes in Markdown is already half the work. Next is to ensure each note has a front matter. For more info on this, check Hugo’s page on Front Matter.
go to top ⤒To automatically add front matter each time you create a note, create a
Python script VimWiki can call. Let’s call this gen-wiki-template and
place it on Vim config directory, say ~/.vim/bin/gen-wiki-template.
The script itself contains the following lines:
#!/usr/bin/python
import sys
import datetime
template = """---
title: ""
date: {date}
draft: false
math: false
---
{{{{< toc >}}}}
"""
date = datetime.date.today()
# if len(sys.argv) < 2
# Expecting filename in YYYY-MM-DD.foo format
# else sys.argv[1].rsplit(".", 1)[0])
print(template.format(date=date))
Let’s break it down:
#!/usr/bin/python tells us that this is a Python script.importing sys and datetime is needed to generate the current
date, which it will fetch from the operating systemtemplate contains the literal multi-line string that is
the front matter of Hugo markdown page
{date} is the variable which will store the value generated by
the function datetime.date.today(). While dates don’t appear in
the wiki itself, they serve as a record for me.{{{{< toc >}}}} will be reduced to {{< toc >}}—my
shortcode for table of contents1—once the note is generated in
markdown. For more info on escaping curly brackets in a Python
script, see this Stackoverflow discussion.print does exactly that: printing the front matter in our
desired format, including the date of generation.Feel free to edit to meet your front matter needs.
go to top ⤒init.vim to call the scriptTo automatically call the script, that is, to add the
front matter, add this line below to your vim init.vim.
au BufNewFile ~/path/to/wiki/*.md :silent 0r !~/.vim/bin/gen-wiki-template '%'
This means that every time a new file (note) is created within the wiki
folder, gen-wiki-template script is run. The script just echoes the
front matter on the blank file.
Having front matter in the wiki is helpful because I can set draft: true and not worry about making a note publicly available yet still
accessible to me (via offline PKM).
At this point, when you generate your site using hugo command, your
wiki should now be included and is ready to be published online.
Edit notes on your Android smartphone by using:
In case you, dear reader, still want to have your own digital garden but cannot be bothered to take on the (relatively) steep learning curve of both Hugo and VimWiki, consider looking into the resource/s below:
Interestingly, to document my shortcodes without activating them, I also had to escape the curly braces here! For more info, see Chris Liatas’s post on “Escaping Hugo Shortcodes” ↩︎
Useful? Consider supporting me.
Back to Index :: Log :: Projects
"Wiki by Hugo and Vimwiki" project is licensed under CC BY-NC 4.0