• Stars
    star
    298
  • Rank 138,832 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Process Obsidian notes to publish them with Hugo. Supports transformation of Obsidian wiki links into Hugo shortcodes for internal linking.


Obsidian Vault to Hugo Content

Lightweight, extensible, zero-dependency CLI written in Python to help us publish obsidian notes with hugo.

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 custom filters to dynamically include/exclude content from processing and processors to do whatever you want with the file contents.

Replacement examples

Obsidian Hugo
[[/some/wiki/link]] [/some/wiki/link]({{< ref "/some/wiki/link" >}})
[[/some/wiki/link|Some text]] [Some text]({{< ref "/some/wiki/link" >}})
[[/some/wiki/link/_index]] [/some/wiki/link/]({{< ref "/some/wiki/link/" >}})
[[/some/wiki/link#Some Heading|Some Heading Link]] [Some Heading Link]({{< ref "/some/wiki/link#some-heading" >}})
==foo bar=== <mark>foo bar</mark>

Note For now, there is no way to escape obsidian wiki links. Every link will be replaced with a hugo link. The only way to get around this is changing the wiki link to don't match the exact sytax, for example by adding an invisible space (Obsidian will highlight the invisible character as a red dot). However, this still is really really not best practice, so if anyone wants to implement real escaping, please do so.

Installation

pip install obsidian-to-hugo

Usage

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.

Python API

from obsidian_to_hugo import ObsidianToHugo

obsidian_to_hugo = ObsidianToHugo(
    obsidian_vault_dir="path/to/obsidian/vault",
    hugo_content_dir="path/to/hugo/content",
)

obsidian_to_hugo.run()

Filters

You can pass an optional filters argument to the ObsidianToHugo constructor. This argument should be a list of functions.

The function will be invoked for each file from the obsidian vault that is copied into the hugo content directory.

Inside the function, you have access to the file path and the file contents.

When the function returns False, the file will be skipped and not copied into the hugo content directory.

from obsidian_to_hugo import ObsidianToHugo

def filter_file(file_contents: str, file_path: str) -> bool:
    # do something with the file path and contents
    if your_condition:
        return True # copy file
    else:
        return False # skip file

obsidian_to_hugo = ObsidianToHugo(
    obsidian_vault_dir="path/to/obsidian/vault",
    hugo_content_dir="path/to/hugo/content",
    filters=[filter_file],
)

obsidian_to_hugo.run()

Processors

You can pass an optional processors argument to the ObsidianToHugo constructor. This argument should be a list of functions.

The function will be invoked for each file from the obsidian vault that is copied into the hugo content directory. It will be passed the file contents as string, and should return the processed version of the file contents.

Custom processors are invoked after the default processing of the file contents.

from obsidian_to_hugo import ObsidianToHugo

def process_file(file_contents: str) -> str:
    # do something with the file contents
    return file_contents

obsidian_to_hugo = ObsidianToHugo(
    obsidian_vault_dir="path/to/obsidian/vault",
    hugo_content_dir="path/to/hugo/content",
    processors=[process_file],
)

obsidian_to_hugo.run()

More Repositories

1

tabgod

execute any javascript on any chromium tabs - cross-tab parallel execution
TypeScript
154
star
2

ghrns

GitHub Repository Naming Suggestion Service: AI powered naming suggestions for your GitHub repositories
JavaScript
18
star
3

replika-chat-export

Export your replika chat messages.
JavaScript
16
star
4

dswav

Python
15
star
5

ebay-kleinanzeigen.de-auto-renew-ads

Automatically renews your offers on ebay-kleinanzeigen.de
PHP
12
star
6

yandex-ranking-factors

Leaked Yandex search ranking factors transformed into JSON and translated into English.
TypeScript
10
star
7

gearchy

Internet's first Goggles manager.
TypeScript
9
star
8

replika-diary-export

Export your entire Replika diary including all images.
JavaScript
7
star
9

e11

fully typed js/ts openapi client for elevenlabs api
TypeScript
4
star
10

hugo-theme-component-search

Make your hugo blog posts searchable.
3
star
11

covid-certificate-decoder-flask

Decode your eu health certificate qr code
HTML
3
star
12

pelican-theme-darksome

Darksome theme for Pelican Static Site Generator
HTML
3
star
13

youtube-unliker

Unlike all previously liked YouTube videos at once.
JavaScript
3
star
14

macos-shortcut-hugo-list-future

Styles for the macOS Shortcut, which visually lists your upcoming Hugo blog posts
Sass
3
star
15

wp-hard

A modern approach to hardening WordPress: A WordPress hardening plugin.
PHP
2
star
16

anxtgo

Personality development and knowledge gaining powered by experiential learning.
Vue
2
star
17

user-styles

Stylus
2
star
18

astro-addons

TypeScript
2
star
19

acf-helper

PHP
2
star
20

cookiecutter-bookmarklet

Boilerplate template to create new bookmarklets blazingly fast.
Dockerfile
2
star
21

CpJsonToImg

Convert Adobe Captivate bundled JSON images back to their source files
PHP
1
star
22

devidwolf.github.io

Personal website
Python
1
star
23

adoc-styles

Monorepo for stylesheets, "skins" and tooling around Asciidoctor document styles.
Sass
1
star
24

eta-slots-plugin

TypeScript
1
star
25

cookiecutter-chromium-extension

Boilerplate template to create new chromium browser extensions blazingly fast.
Sass
1
star
26

hugo-theme-component-oembed

Static oEmbed endpoint for Hugo websites
HTML
1
star
27

invoice

Simple tool to generate invoices right from your browser by using its print API for PDF saving.
JavaScript
1
star
28

hashnode-gh-src-new

Bash Script to automatically create new hashnode .md article files with frontmatter
Shell
1
star
29

hugoseotheme.com

Website of the SEO theme for HUGO. Features, Articles, Examples, Documentation.
AsciiDoc
1
star
30

ipfs-blogs

A list of decentralized blogs running on IPFS.
Python
1
star
31

google-untitled-spam-spider

A spam spider which is targeting 'Untitled' spam pages from the Google search results.
Python
1
star
32

cookiecutter

GitHub template repository for cookiecutter repositories.
Shell
1
star
33

hugo-theme-component-structured-data

Hugo Theme Component for Structured Data
HTML
1
star
34

BookmarkToShortcut

Convert your browser bookmarks to web shortcut files (.url, .webloc, .desktop) to be able to use them on your desktop and in your file explorer.
Python
1
star
35

wp-hook

Generate WordPress add_action and add_filter hooks on the fly.
Dockerfile
1
star
36

anxtgo.nvim

TypeScript
1
star