Plugin for keeping the filename and first heading of a file in sync

On popular request, it is now possible to set regex ignore patterns

This can be used to, for example:

  • Ignore everything under a specific folder: templates/
  • Everything that has tmp in the name: tmp
  • Everything that has a series of numbers followed by a dash (like 123456 - Hello.md): [0-9]+\ \-\
6 Likes

Is there any chance an option could be added to make this work in one direction? Maybe a three-option selector:

  • Filename <-> Heading
  • Filename → Heading
  • Heading → Filename

My own use case is strictly that last one, where I always adjust the filename to match whatever I’ve changed the heading to, and not the other way around.

To go with this, it would be useful to have an way to set what illegal characters get replaced with in a filename - by default an empty string (“Test: Thing” becomes “Test Thing”), but some might wish to set it to “-” or other placeholders (“Test: Thing” becomes “Test- Thing”).

4 Likes

Useful plugin for me! Save me much time. Thanks a lot!
Is it possible to skip YAML attributes block and start searching 1-st header after the attributes block? Otherwise, it breaks the attributes.

Any progress on this?

This. I have a bunch of ill-named .md files that I’d like to fix from their contents i.e. from the title inside the file.

Hello. I’ve found a bug that was caused by your plugin.

Description

Double open the same note via a link from a note which has been added in the sidebar, delete all content inside this note.

Steps to reproduce

  1. Add a note to the sidebar
  2. Add a link to another note inside this note
  3. Click the link and then click to open the second tab with this note
  4. All content is deleting in a note that the link refers to

Screen capture: iCloud

Expected result

Content isn’t deleting when double-clicking on a link in a sidebar note.

Environment

  • Operating system: MacOS 12.0 beta
  • Obsidian version: 0.12.10
1 Like

Hi! I’m the author of that plugin but wasn’t able to reproduce your issues no matter what I tried. I still added a few changes to harden the plugin.

Do you have some steps to reproduce? Can you post a list with all plugins you have installed? It feels to me it might be an interaction between 2 things

Github thread: Data-loss · Issue #18 · dvcrn/obsidian-filename-heading-sync · GitHub

BTW I have also added support for YAML frontmatter skipping and squashed a few other smaller bugs in the same step.

New update will be out in a bit

5 Likes

I’ve had the same issue. My active plugins are:

  • Sliding Panes (Andy’s Mode)
  • Tag wrangler
  • Shortcuts extender
  • Style Settings
  • Hider

thanks, your plugin is precious!!

1 Like

Do you have some steps to reproduce this?

I’ve pushed v1.4.0 with some bug fixes and frontmatter support. Please update if this issue pops up again

This is most helpful! Thanks. And thanks for the update to allow excluding files. That really made it possible for me to safely install this! :grinning:

1 Like

When I add a link in a note, then I “cmd click” on this link, it creates a file with the link as filename but then the plugin doesn’t create the title . Normal?

1.5.0 has been released today which should address this. Can you give it a try?

I love this plug in, and it is incredibly useful but I think it has been corrupting the image files that are in my vault. Here is what I tracked down this morning:

Data Loss when using Filename Header Sync

I have not looked at the code yet, but maybe add a guard to ignore any filetypes other than .md?

Thanks for reporting, this was addressed immediately and the faulty version unpublished+blacklisted. 1.5.1 has a strict guard to only act on markdown files

1 Like

Hy @sararkin

My question isn’t related about your plugin. Can you show me how did you set-up these marked lines to show in your pane.

1 Like

I believe he linked it up thread but the tool there is now deprecated and it’s just a Backlinks in Document toggle

@sararkin
I’m just a noob with javascript, but I may have found a way to improve a piece of your code.

(I don’t know how to use GitHub yet, otherwise I would make a push request or whatever it is called)

I tried putting a [[wiki-link]] in the first header, thinking the square brackets would automatically get filtered out. Instead, I was confused when only one pair of brackets was removed, and other similarly strange results.

Looking at your code, I found the culprit: the function sanitizeHeading() (line 231 in main.ts) uses replace(string, '') instead of replace(regExp, '').

I think I figured out how to do it on GitHub.

I don’t know what happen with this plugin when used with obsidian sync. When I update the H1 title, the filename is adapted, but then I have duplicate files.
Ex:
I have a note the-book.md
I open this node and change heading: # the-book becomes # B-the-book
the plugin updates automatically the filename
but then I see 2 files:

  • the-book.md
  • B-the-book.md

+2!

Synching the Frontmatter Title to the file name as an option would be a terrific benefit!

Cheers!