Make a backup

Before any mass changes, always make a copy of your Obsidian vault. Even if everything works perfectly — mistakes happen. Also, to minimise the risk, I recommend the manual method.


🎯 What do we want to replace?

Notes used to start like this:

The links template I currently have:

This format:

  • isn’t read by the Dataview plugin
  • interferes with the note’s structure
  • requires manual editing

We want to move to YAML:

What the YAML template looks like:

And here’s what the YAML looks like as source code:

---
input links:
  - '[[PSYCHOLOGY]]'
tags:
  - psychology
  - blog
date: 24-05-2025
---

And the display of backlinks can be moved to the start of the note. How? Let’s look at it below.


Instead of Output links with [[Dataview]] code, we now use:

  • built-in backlinks (enabled in the settings)

What "Backlinks" look like:


  1. Open the CSS snippets folder:

The CSS snippets folder:

  1. Create a CSS document (first create an ordinary notepad file “Save as” “All formats” just add .css to the file name e.g. backlinks.css)

  2. Add this code to publish.css or obsidian.css:

.cm-sizer {
  display: flex;
  flex-direction: column;
}

.inline-title {
  order: 1;
}

.metadata-container {
  order: 2;
}

.embedded-backlinks {
  order: 3;
  position: static;
  overflow-y: auto;
  max-height: 300px;
}

.cm-contentContainer {
  order: 4;
}

What the code looks like in a notepad (css):

👉 Now the backlinks will be right under the YAML block. This is convenient for quickly viewing your connections.


🔁 3 ways to move to YAML

1. 🐍 A Python script (for the experienced)

# See below — be sure to change the path to your Vault (Vault_Path) and check the search template

Warning! This method mass-replaces text. Don't run it if you're not sure. Better consult ChatGPT before running.

Here’s the code itself:

import os
import re

VAULT_PATH = r"C:\delete after\Tutorial 01"

# A flexible regex: allows optional spaces, line breaks and the absence of some fields
pattern = re.compile(
    r"(?:)?",
    re.DOTALL
)

def convert_file(filepath):
    with open(filepath, "r", encoding="utf-8") as f:
        content = f.read()

    if content.strip().startswith("---"):
        return False

    match = pattern.search(content)
    if not match:
        return False

    input_raw = match.group(1).strip()
    tags_raw = match.group(2).strip()
    date = match.group(3).strip() if match.group(3) else None

    # Formatting the links: '[[...]]'
    input_links = re.findall(r"\[\[(.*?)\]\]", input_raw)
    input_yaml = "\n".join([f"  - '[[{link.strip()}]]'" for link in input_links])

    # Formatting the tags
    tags = [tag.strip("# ").strip() for tag in tags_raw.split()]
    tags_yaml = "\n".join([f"  - {tag}" for tag in tags]) if tags else "  - "

    # Building the YAML
    yaml = [
        "---",
        "input links:",
        input_yaml if input_yaml else "  - ",
        "tags:",
        tags_yaml,
    ]
    if date:
        yaml.append(f"date: {date}")
    yaml.append("---")

    # Remove the whole old block and add the YAML
    new_content = "\n".join(yaml) + "\n\n" + content[match.end():].lstrip()

    with open(filepath, "w", encoding="utf-8") as f:
        f.write(new_content)

    print(f"✅ Updated: {filepath}")
    return True

def process_vault():
    print("🚀 Starting processing...")
    count = 0
    for root, _, files in os.walk(VAULT_PATH):
        for file in files:
            if file.endswith(".md"):
                full_path = os.path.join(root, file)
                if convert_file(full_path):
                    count += 1
    print(f"🎉 Done! Files updated: {count}")

if __name__ == "__main__":
    process_vault()
    

How to adapt it for yourself?

  1. Change VAULT_PATH to the path of your vault

  2. Show this code to ChatGPT and write: “Help me adapt it to my templates. Here's an example note…“


2. 🔍 The Global Search and Replace plugin

Good for template strings. For example:

  • Find: ...%% block
  • Enable backlinks and use CSS so they’re at the top

📌 Conclusion

Moving to YAML is about order: you get rid of manual code, use Obsidian's built-in features and tidy up your system.

Want an example of adapting it to your Vault? Write to ChatGPT:

“Here’s what my old template looked like. Help me redo it in YAML and explain which lines I can insert manually.”


Keep going?