- Notifications
You must be signed in to change notification settings - Fork29
Process Obsidian notes to publish them with Hugo. Supports transformation of Obsidian wiki links into Hugo shortcodes for internal linking.
License
devidw/obsidian-to-hugo
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Lightweight, extensible, zero-dependency CLI written in Python to help us publishobsidian notes withhugo.
It only takes two arguments: The obsidian vault directory (--obsidian-vault-dir
) and the hugo content directory (--hugo-content-dir
).
python -m obsidian_to_hugo --obsidian-vault-dir=<path> --hugo-content-dir=<path>
It takes care of the following steps:
- Clears hugo content directory (directory will be deleted and recreated)
- Copies obsidian vault contents into hugo content directory (
.obsidian
gets removed immediately after copying) - Replaces obsidian wiki links (
[[wikilink]]
) with hugo shortcode links([wikilink]({{< ref "wikilink" >}})
) - Replaces obsidian marks (
==important==
) with HTML marks (<mark>important</mark>
) - Want to do more? You can write and register customfilters to dynamicallyinclude/exclude content from processing andprocessors to do whateveryou want with the file contents.
NoteFor now, there isno way to escape obsidian wiki links. Every linkwill be replaced with a hugo link. The only way to get around this is changingthe wiki link to don't match the exact sytax, for example by adding aninvisible space (Obsidian will highlight the invisible character as a red dot).
However, this still is really reallynot bestpractice, so if anyone wants to implement real escaping,please doso.
pip install obsidian-to-hugo
usage: __main__.py [-h] [--version] [--hugo-content-dir HUGO_CONTENT_DIR] [--obsidian-vault-dir OBSIDIAN_VAULT_DIR]options: -h, --help show this help message and exit --version, -v Show the version and exit. --hugo-content-dir HUGO_CONTENT_DIR Directory of your Hugo content directory, the obsidian notes should be processed into. --obsidian-vault-dir OBSIDIAN_VAULT_DIR Directory of the Obsidian vault, the notes should be processed from.
fromobsidian_to_hugoimportObsidianToHugoobsidian_to_hugo=ObsidianToHugo(obsidian_vault_dir="path/to/obsidian/vault",hugo_content_dir="path/to/hugo/content",)obsidian_to_hugo.run()
You can pass an optionalfilters
argument to theObsidianToHugo
constructor. This argument should be a list of functions.
The function will be invoked for each file from the obsidian vault that iscopied into the hugo content directory.
Inside the function, you have access to the file path and the file contents.
When the function returnsFalse
, the file will be skipped and not copiedinto the hugo content directory.
fromobsidian_to_hugoimportObsidianToHugodeffilter_file(file_contents:str,file_path:str)->bool:# do something with the file path and contentsifyour_condition:returnTrue# copy fileelse:returnFalse# skip fileobsidian_to_hugo=ObsidianToHugo(obsidian_vault_dir="path/to/obsidian/vault",hugo_content_dir="path/to/hugo/content",filters=[filter_file],)obsidian_to_hugo.run()
You can pass an optionalprocessors
argument to theObsidianToHugo
constructor. This argument should be a list of functions.
The function will be invoked for each file from the obsidian vault that iscopied into the hugo content directory. It will be passed the file contentsas string, and should return the processed version of the file contents.
Custom processors are invoked after the default processing of the file contents.
fromobsidian_to_hugoimportObsidianToHugodefprocess_file(file_contents:str)->str:# do something with the file contentsreturnfile_contentsobsidian_to_hugo=ObsidianToHugo(obsidian_vault_dir="path/to/obsidian/vault",hugo_content_dir="path/to/hugo/content",processors=[process_file],)obsidian_to_hugo.run()
About
Process Obsidian notes to publish them with Hugo. Supports transformation of Obsidian wiki links into Hugo shortcodes for internal linking.