basham / obsidian-alias-from-heading

Obsidian plugin: Implicitly add an alias matching the first heading in a document.
MIT License
16 stars 1 forks source link

Alias from heading

Aliases in Obsidian make it convenient to provide display names to note links. However, there are a few pain points:

This plugin resolves these problems in the following ways:

Example

Without this plugin, an alias would need to be explicitly defined in YAML. It is a manual process to keep the alias in sync with the first heading in the note.

<!-- 2022-06-08-1030.md -->

---
aliases: "🍅 Build a garden"
---

# 🍅 Build a garden

- Survey the yard
- Choose a design
- Purchase materials
- Build the frame
- Prepare the ground
- Fill the bed

With this plugin, the alias front matter is no longer needed.

<!-- 2022-06-08-1030.md -->

# 🍅 Build a garden

- Survey the yard
- Choose a design
- Purchase materials
- Build the frame
- Prepare the ground
- Fill the bed

This second note links to the first note with only the file name.

<!-- 2022-02-02-1445.md -->

# 🥬 Gardening projects

- [[2022-06-08-1030]]
- Germinate seeds
- ...

However, it is often more readable to link to the note with a friendly display name. Type [[, search for the note by its heading, and select it to insert it.

<!-- 2022-02-02-1445.md -->

# 🥬 Gardening projects

- [[2022-06-08-1030|🍅 Build a garden]]
- Germinate seeds
- ...

Now that the display name matches the first heading of the note it links to, they stay in sync. Update the heading in the first note from 🍅 Build a garden to 🥕 Build a raised garden bed. Now the second note displays the change.

<!-- 2022-02-02-1445.md -->

# 🥬 Gardening projects

- [[2022-06-08-1030|🥕 Build a raised garden bed]]
- Germinate seeds
- ...

If all headings are removed from the first note, any links that were kept in sync are updated so that their display name matches the file name. This behavior makes it easy to later insert a new heading while keeping any link display names in sync. It also makes the preview of the link still meaningful, in the meantime.

<!-- 2022-02-02-1445.md -->

# 🥬 Gardening projects

- [[2022-06-08-1030|2022-06-08-1030]]
- Germinate seeds
- ...

If a custom display name is wanted or none at all, just manually change it inline. It will not be kept in sync with the heading, unless it is manually changed back to match the heading.

<!-- 2022-02-02-1445.md -->

# 🥬 Gardening projects

- [[2022-06-08-1030|🌽 Garden bed]]
- Germinate seeds
- ...

Development

See: Obsidian Developer Docs