obsidian-to-hugo


Nameobsidian-to-hugo JSON
Version 12023.3.21 PyPI version JSON
download
home_page
SummaryProcess Obsidian notes to publish them with Hugo. Transforms Obsidian wiki links into Hugo shortcodes for internal linking.
upload_time2023-03-21 15:14:38
maintainer
docs_urlNone
author
requires_python>=3.6
licenseMIT
keywords obsidian hugo markdown wikilink
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align=center>
<img src=https://raw.githubusercontent.com/devidw/obsidian-to-hugo/master/img/gopher-obsidian.png width=100 height=100>
<br>
Obsidian Vault to Hugo Content
</h1>

<p align="center">
<a href="https://obsidian-to-hugo.wolf.gdn" target="_blank">
<img src="https://raw.githubusercontent.com/devidw/obsidian-to-hugo/master/img/demo.gif">
</a>
</p>

Lightweight, extensible, zero-dependency CLI written in Python to help us publish [obsidian](https://obsidian.md) notes with [hugo](https://gohugo.io). 

It only takes two arguments: The obsidian vault directory (`--obsidian-vault-dir`) and the hugo content directory (`--hugo-content-dir`).

```console
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](#filters) to dynamically
  include/exclude content from processing and [processors](#processors) to do whatever
  you want with the file contents.


## Replacement examples

| Obsidian | Hugo
| -------- | --------
| ![](https://raw.githubusercontent.com/devidw/obsidian-to-hugo/master/img/obsidian.png) | ![](https://raw.githubusercontent.com/devidw/obsidian-to-hugo/master/img/hugo.png)
| `[[/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](https://en.wikipedia.org/wiki/Zero-width_space) (Obsidian will highlight the invisible character as a red dot).
> ![](https://raw.githubusercontent.com/devidw/obsidian-to-hugo/master/img/do-not-do-that.png)
> However, this still is really really *not* best
> practice, so if anyone wants to implement real escaping, [please do
> so](https://github.com/devidw/obsidian-to-hugo/pulls).


## Installation

```console
pip install obsidian-to-hugo
```


## Usage

```console
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

```python
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.

```python
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.

```python
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()
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "obsidian-to-hugo",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "obsidian,hugo,markdown,wikilink",
    "author": "",
    "author_email": "David Wolf <d@wolf.gdn>",
    "download_url": "https://files.pythonhosted.org/packages/b9/f2/9b6e3121e24097f9eb61978840288905f9f9059b87786df674baee169274/obsidian_to_hugo-12023.3.21.tar.gz",
    "platform": null,
    "description": "<h1 align=center>\n<img src=https://raw.githubusercontent.com/devidw/obsidian-to-hugo/master/img/gopher-obsidian.png width=100 height=100>\n<br>\nObsidian Vault to Hugo Content\n</h1>\n\n<p align=\"center\">\n<a href=\"https://obsidian-to-hugo.wolf.gdn\" target=\"_blank\">\n<img src=\"https://raw.githubusercontent.com/devidw/obsidian-to-hugo/master/img/demo.gif\">\n</a>\n</p>\n\nLightweight, extensible, zero-dependency CLI written in Python to help us publish [obsidian](https://obsidian.md) notes with [hugo](https://gohugo.io). \n\nIt only takes two arguments: The obsidian vault directory (`--obsidian-vault-dir`) and the hugo content directory (`--hugo-content-dir`).\n\n```console\npython -m obsidian_to_hugo --obsidian-vault-dir=<path> --hugo-content-dir=<path>\n```\n\nIt takes care of the following steps:\n\n- Clears hugo content directory (directory will be deleted and recreated)\n- Copies obsidian vault contents into hugo content directory (`.obsidian` gets removed immediately after copying)\n- Replaces obsidian wiki links (`[[wikilink]]`) with hugo shortcode links\n  (`[wikilink]({{< ref \"wikilink\" >}})`)\n- Replaces obsidian marks (`==important==`) with HTML marks (`<mark>important</mark>`)\n- Want to do more? You can write and register custom [filters](#filters) to dynamically\n  include/exclude content from processing and [processors](#processors) to do whatever\n  you want with the file contents.\n\n\n## Replacement examples\n\n| Obsidian | Hugo\n| -------- | --------\n| ![](https://raw.githubusercontent.com/devidw/obsidian-to-hugo/master/img/obsidian.png) | ![](https://raw.githubusercontent.com/devidw/obsidian-to-hugo/master/img/hugo.png)\n| `[[/some/wiki/link]]` | `[/some/wiki/link]({{< ref \"/some/wiki/link\" >}})`\n| `[[/some/wiki/link\\|Some text]]` | `[Some text]({{< ref \"/some/wiki/link\" >}})`\n| `[[/some/wiki/link/_index]]` | `[/some/wiki/link/]({{< ref \"/some/wiki/link/\" >}})`\n| `[[/some/wiki/link#Some Heading\\|Some Heading Link]]` | `[Some Heading Link]({{< ref \"/some/wiki/link#some-heading\" >}})`\n| `==foo bar===` | `<mark>foo bar</mark>`\n\n> **Note**\n> For now, there is *no way to escape* obsidian wiki links. Every link\n> will be replaced with a hugo link. The only way to get around this is changing\n> the wiki link to don't match the exact sytax, for example by adding an\n> [invisible space](https://en.wikipedia.org/wiki/Zero-width_space) (Obsidian will highlight the invisible character as a red dot).\n> ![](https://raw.githubusercontent.com/devidw/obsidian-to-hugo/master/img/do-not-do-that.png)\n> However, this still is really really *not* best\n> practice, so if anyone wants to implement real escaping, [please do\n> so](https://github.com/devidw/obsidian-to-hugo/pulls).\n\n\n## Installation\n\n```console\npip install obsidian-to-hugo\n```\n\n\n## Usage\n\n```console\nusage: __main__.py [-h] [--version] [--hugo-content-dir HUGO_CONTENT_DIR]\n                   [--obsidian-vault-dir OBSIDIAN_VAULT_DIR]\n\noptions:\n  -h, --help            show this help message and exit\n  --version, -v         Show the version and exit.\n  --hugo-content-dir HUGO_CONTENT_DIR\n                        Directory of your Hugo content directory, the obsidian notes\n                        should be processed into.\n  --obsidian-vault-dir OBSIDIAN_VAULT_DIR\n                        Directory of the Obsidian vault, the notes should be processed\n                        from.\n```\n\n## Python API\n\n```python\nfrom obsidian_to_hugo import ObsidianToHugo\n\nobsidian_to_hugo = ObsidianToHugo(\n    obsidian_vault_dir=\"path/to/obsidian/vault\",\n    hugo_content_dir=\"path/to/hugo/content\",\n)\n\nobsidian_to_hugo.run()\n```\n\n\n### Filters\n\nYou can pass an optional `filters` argument to the `ObsidianToHugo`\nconstructor. This argument should be a list of functions.\n\nThe function will be invoked for each file from the obsidian vault that is\ncopied into the hugo content directory.\n\nInside the function, you have access to the file path and the file contents.\n\nWhen the function returns `False`, the file will be skipped and not copied\ninto the hugo content directory.\n\n```python\nfrom obsidian_to_hugo import ObsidianToHugo\n\ndef filter_file(file_contents: str, file_path: str) -> bool:\n    # do something with the file path and contents\n    if your_condition:\n        return True # copy file\n    else:\n        return False # skip file\n\nobsidian_to_hugo = ObsidianToHugo(\n    obsidian_vault_dir=\"path/to/obsidian/vault\",\n    hugo_content_dir=\"path/to/hugo/content\",\n    filters=[filter_file],\n)\n\nobsidian_to_hugo.run()\n```\n\n\n### Processors\n\nYou can pass an optional `processors` argument to the `ObsidianToHugo`\nconstructor. This argument should be a list of functions.\n\nThe function will be invoked for each file from the obsidian vault that is\ncopied into the hugo content directory. It will be passed the file contents\nas string, and should return the processed version of the file contents.\n\nCustom processors are invoked after the default processing of the file contents.\n\n```python\nfrom obsidian_to_hugo import ObsidianToHugo\n\ndef process_file(file_contents: str) -> str:\n    # do something with the file contents\n    return file_contents\n\nobsidian_to_hugo = ObsidianToHugo(\n    obsidian_vault_dir=\"path/to/obsidian/vault\",\n    hugo_content_dir=\"path/to/hugo/content\",\n    processors=[process_file],\n)\n\nobsidian_to_hugo.run()\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Process Obsidian notes to publish them with Hugo. Transforms Obsidian wiki links into Hugo shortcodes for internal linking.",
    "version": "12023.3.21",
    "split_keywords": [
        "obsidian",
        "hugo",
        "markdown",
        "wikilink"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "db0a38aeab39044544bd683e5f9d190faef25a13125c8314da7798f848f2f95f",
                "md5": "2444e433c590321787550ef8a35d3d65",
                "sha256": "af2fce20bdfee9234472bc250567195e928dfa549451314c89419c2ba79d7883"
            },
            "downloads": -1,
            "filename": "obsidian_to_hugo-12023.3.21-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2444e433c590321787550ef8a35d3d65",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7578,
            "upload_time": "2023-03-21T15:14:36",
            "upload_time_iso_8601": "2023-03-21T15:14:36.298680Z",
            "url": "https://files.pythonhosted.org/packages/db/0a/38aeab39044544bd683e5f9d190faef25a13125c8314da7798f848f2f95f/obsidian_to_hugo-12023.3.21-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b9f29b6e3121e24097f9eb61978840288905f9f9059b87786df674baee169274",
                "md5": "9a03370c56d90f8caa7d5a017e13138f",
                "sha256": "14c9ad0f60cdb40b095b047f96c89a6a936fc28a3905d6555ebf38479e813e74"
            },
            "downloads": -1,
            "filename": "obsidian_to_hugo-12023.3.21.tar.gz",
            "has_sig": false,
            "md5_digest": "9a03370c56d90f8caa7d5a017e13138f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 8480,
            "upload_time": "2023-03-21T15:14:38",
            "upload_time_iso_8601": "2023-03-21T15:14:38.011983Z",
            "url": "https://files.pythonhosted.org/packages/b9/f2/9b6e3121e24097f9eb61978840288905f9f9059b87786df674baee169274/obsidian_to_hugo-12023.3.21.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-21 15:14:38",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "obsidian-to-hugo"
}
        
Elapsed time: 0.04535s