Auto Frontmatter on Folder Structure

unlisted

by Pine885

Automatically tags notes and creates structural links (siblings, parents, children) based on folder hierarchy.

★ 1 starsUpdated 20d agoGPL-3.0
View on GitHub

Auto Frontmatter

Obsidian plugin that derives tags and structural frontmatter links from the vault folder hierarchy.

The plugin treats folder paths as the source of truth. For each markdown note it can write path-derived tags, links to related notes in parent, sibling, child, and cousin folders, and plain-text summaries extracted from folder-level summary notes. All structural writes go through app.fileManager.processFrontMatter.

  • Plugin ID: obsidian-auto-frontmatter
  • Version: 4.2.0
  • Minimum Obsidian version: 1.0.0
  • Desktop only: no

Behavior

For a note at Projects/Active/Work/Task.md:

  • Path tags are derived from Projects, Active, and Work, limited by Tag Depth.
  • Sibling links come from other notes in Work.
  • Parent links come from notes in Active (level 1), Projects (level 2), and so on.
  • Child links come from notes in subfolders of Work (level 1), their subfolders (level 2), and so on.
  • Cousin links come from notes in every vault folder whose name matches a user-authored FolderName-[R] key.
  • Summary keys are added when a summary note is found in the corresponding folder and Enable Summary is on.

Frontmatter keys

Structural keys use a suffix code. The regex /-\[(S|P\d+|C\d+|R|TS|TP\d+|TC\d+|TR)\]$/ identifies plugin-owned keys. Keys matching this regex that are not produced during an update are deleted as obsolete.

SuffixMeaningValue
-[P n]Parent notes at level nList of [[basename]] links
-[TP n]Parent folder summary at level nPlain text
-[S]Siblings in the current folderList of [[basename]] links
-[TS]Summary of the current folderPlain text
-[C n]Child notes at level nList of [[basename]] links
-[TC n]Child folder summary at level nPlain text
-[R]Cousins; user-authored input keyList of links, or [No matching folder found]
-[TR]Cousin folder summaryPlain text

Level numbering:

  • Parent level 1 is the parent of the note's containing folder, not the containing folder itself.
  • Child level 1 is a direct subfolder of the note's containing folder.
  • Sibling and sibling-summary keys use the containing folder name.

FolderName-[R] is user-authored and preserved across updates. When linking is enabled, the plugin writes resolved links to the same key and adds the folder name to tags when tagging is enabled. When linking is disabled, existing -[R] keys are preserved with an empty list value.

All other non-structural frontmatter keys are preserved.

Example

Note path: Projects/Active/Work/Task.md Settings: Tag Depth = 2, Link Depth = 2, Enable Tagging, Enable Linking, Enable Summary User-authored key: Resources-[R]

tags:
  - Active
  - Work
Active-[P1]:
  - "[[Active Folder Note]]"
Active-[TP1]: "Current active projects."
Projects-[P2]:
  - "[[Project Root]]"
Projects-[TP2]: "The main project hub."
Work-[S]:
  - "[[Note A]]"
  - "[[Note B]]"
Work-[TS]: "Work-related tasks and notes."
Work-[C1]:
  - "[[Sub-task 1]]"
  - "[[Sub-task 2]]"
Work-[TC1]: "Detailed sub-task breakdown."
Resources-[R]:
  - "[[Resource A]]"
  - "[[Resource B]]"
Resources-[TR]: "Global resource library."

Key order is parents, siblings, children, cousins, followed by preserved non-structural keys. Order is enforced on write. With Force Key Sorting disabled, a file is not rewritten when the computed frontmatter is equal to the existing frontmatter, regardless of key order.

Tags

Tags are derived from folder path segments excluding the filename.

  • Tag Depth = 0: clears the tags property.
  • Tag Depth = 1: uses the immediate parent folder only.
  • Tag Depth >= 2: uses up to the last n path segments.
  • Default: 99.

Folder names are sanitized by replacing whitespace, path separators, brackets, braces, quotes, pipes, colons, hashes, asterisks, question marks, angle brackets, and similar characters with _. Repeated underscores are collapsed. Segments with no remaining alphanumeric content are dropped.

When tagging is enabled, the plugin replaces the existing tags property with the computed path tags plus any cousin folder names. It does not merge with user-authored tags.

Summaries

Summary detection runs in each relevant folder:

  • With Strict Summary Name enabled, a file whose basename equals summary (case-insensitive) is used.
  • Otherwise, markdown files in the folder are matched against Summary Detection Priority, default Exact > StartsWith > EndsWith > Contains. Matching is case-insensitive against the basename.

Summary text processing:

  • YAML frontmatter is removed using metadataCache.frontmatterPosition; a regex fallback is used when position data is unavailable.
  • With Full Text disabled, the first paragraph that does not start with # is used.
  • Wikilinks are reduced to their display text or target.
  • Bold, italic, strikethrough, inline-code markers, leading heading markers, and horizontal rules are stripped.

Summaries are written for parents, the current folder (siblings), children, and cousins when enabled.

Settings

Settings are grouped into Main, Automation, Tag, Link, and Summary tabs. All feature toggles are disabled by default.

Main

  • Run Auto-Frontmatter: processes all markdown files in scope.
  • Whitelisted Folders: comma-separated folder filters. Empty means all folders.
  • Blacklisted Folders: comma-separated folder filters, applied before the whitelist.
  • Ribbon toggles: run-all, active-note update, clear-all, clear-active. Ribbon changes require a plugin reload.
  • Clear All Frontmatter: removes every frontmatter property from every in-scope markdown note. This is destructive and includes user-authored keys. A confirmation dialog is shown.
  • Clear Active-Note Frontmatter: same operation for the active note.

Folder filter matching: an entry containing / is treated as a path prefix; otherwise it matches any path segment. Blacklist takes precedence over whitelist.

Automation

  • Enable Automation: default off. When enabled, updates are queued on active-leaf-change, rename, and delete vault events.
  • Force Key Sorting: rewrites files even when values are unchanged if key order differs. Higher CPU cost.
  • Update Delay: debounce interval in milliseconds, default 500.

Tag

  • Enable Tagging: default off.
  • Tag Depth: integer, default 99.

Link

  • Enable Linking: default off.
  • Link Depth: 0 disables parent, sibling, and child links but still resolves cousin keys; 1 adds siblings; 2+ adds parents and children. Default 99.

Summary

  • Enable Summary: default off.
  • Unlink Summary Notes: excludes detected summary files from structural link lists.
  • Full Text: default off.
  • Strict Summary Name: default off.
  • Summary Detection Priority: display of the active priority string.

Automation details

  • active-leaf-change queues the active file.
  • File rename queues the renamed file and the old and new folders plus their parent folders.
  • File delete queues the containing folder and its parent folder.
  • Folder create and delete maintain the in-memory folder cache; folder rename updates the cache and queues the renamed folder recursively.
  • Queue processing is debounced by Update Delay. A notice reports the number of updated files and failures.

Updates are computed twice for each file: once as a pre-flight comparison against cached frontmatter, and once inside the processFrontMatter callback for the actual write. Both paths call the same buildTargetMap logic.

Installation

Manual installation:

  1. Copy main.js and manifest.json to <vault>/.obsidian/plugins/obsidian-auto-frontmatter/.
  2. Enable the plugin in Obsidian community plugin settings.
  3. Open the plugin settings and enable the desired features.

Build

cd auto-frontmatter-raw
npm install
npm run build

npm run build runs tsc and emits main.js in auto-frontmatter-raw/ (outDir: "."). tsconfig.json includes only main.ts and uses strict: true, module: CommonJS, and target: ESNext.

Ribbon icons are inline SVG strings stored in the ICON_SVGS constant at the end of main.ts. Regenerate that block from assets/auto-frontmatter-SVGs/ with:

bash update-ts-SVGs.sh

The script rewrites everything from the const ICON_SVGS = { line onward, so ICON_SVGS must remain last.

Limitations

  • The folder cache is built on load and maintained on folder create, rename, and delete. Bulk external changes can leave cousin lookup stale until the plugin is reloaded.
  • Cousin link resolution scans all folders with a matching name. Cousin summary lookup uses the first matching folder only.
  • Automation can produce frequent writes in large vaults and may interact with cloud sync clients.
  • Clear All Frontmatter removes user-authored properties as well as plugin-managed ones.

For plugin developers

Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.