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

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!

+3
For syncing frontmatter title.

Iā€™m trying to have this plug-in ignore my template files, because it otherwise inserts #Untitled at the end of each new file. Iā€™ve set the Ignore Regex Rule to /* Bins/Templates since my templates are in * Bins/Templates:
2022-02-11-1114-07
But itā€™s still putting #Untitled at the end of the files.

What am I doing wrong?

Thanks,
Russell

My regex rule is actually: /\* Bins/Templates

Am I dealing with the asterisk correctly?

Does it display your templates in the settings page to show that they are ignored?

I think the correct regex would be .*Bins\/Templates.*, can you give that a go?

With your regex, the templates are now displayed in the settings page. However, Iā€™m still getting # Untitled inserted at the end of the note.

Hereā€™s the template file:

And hereā€™s the result:

Maybe itā€™s coming from some other plug-in? Iā€™m just using the core Templates plug-in.

Thanks for your kind help!

Best,
Russell

Is the title of the document ā€œUntitledā€? You can easily test this by deactivating filename-heading-sync and see if it still happens

With filename-heading-sync DEACTIVATED, and the core Templates plug-in ACTIVATED, I get a new file with ā€œUntitledā€ in the filename field, whether or not the template has an H1 heading.

With filename-heading-sync ACTIVATED, and the core Templates plug-in ACTIVATED, I get a new file with ā€œUntitledā€ in the filename field AND # Untitled inserted at the end of the file, whether or not the template has an H1 heading.

It must be something unique to my setting. Iā€™ll keep digging around, as I have time.

Thanks,
Russell

Thank you so much!

1.6 has been released which adds a option to disable the file-open event hook. Some people were reporting issues with templater because both plugins act on file-open. Disabling file-open for those cases should hopefully fix issues

I suggest to have both options to whitelist/include and blacklist/exclude files, instead of having only the exclude option

I have the title that changes twice in my files. Is there a new fonction of obsidian that does the same as filename heading sync now ?

Obsidian shows the file name above the current pane since 1.0. Depends on what you want - do you want the heading as part of the markdown document or are you okay with the obsidian display?

For myself, I turned off the Obsidian feature because I want all the information semantically in my files

is it possible to set different level heading sync to filename, or just sync the first heading(no matter what level it is) to filename

1 Like