i ceate md file outside obsidian,when open in obsidian,banner: xxx repeat in top of file
czcz1024 opened this issue · 6 comments
create a file in explorer and type
banner: some img url
save it to a md file
and then open it in obsidian.
there are changed by this plugin to
banner: ...
banner: ...
this plugin repeat the banner yaml,it will make the other yaml all disable
I think what @czcz1024 is trying to say here is that when we create .md files outside of obsidian with a FileAppend command (or in my case within some plugin code app.vault.adapter.append()
) and try to add front matter and set the "banner" key/value, the file gets created, the banner works, however the meta data/front matter section is duplicated.
In this example, I wrote text to the file and set the banner using single quotes and a sample "meta: 'data'
" pair. The banner is displaying properly, however the front matter section is missing my meta key and the banner has double quotes. And, finally my front matter section is pushed down and rendered in view mode as well. Something funny is going on.
What am I doing wrong or incorrectly assuming?
This does not happen if creating the frontmatter manually. Even with my plugin I'm developing and writing frontmatter to a file, Banners is creating it's own frontmatter section above mine which leaves my meta data looking like just normal text with a solid line above it.
Here's another example in source mode:
this has occurred to me after backing up my obsidian vault using obsidian git plugin. The banner image is added by linking it right below the actual banner. It happened to all notes which had a banner. This may need a fix.
I think what @czcz1024 is trying to say here is that when we create .md files outside of obsidian with a FileAppend command (or in my case within some plugin code
In this example, I wrote text to the file and set the banner using single quotes and a sample "`meta: 'data'`" pair. The banner is displaying properly, however the front matter section is missing my meta key and the banner has double quotes. And, finally my front matter section is pushed down and rendered in view mode as well. Something funny is going on.app.vault.adapter.append()
) and try to add front matter and set the "banner" key/value, the file gets created, the banner works, however the meta data/front matter section is duplicated.What am I doing wrong or incorrectly assuming?
Experiencing the same thing when opening my vault on a different computer when synced via git.
I experience the same issue, I use python to update my notes outside of obsidian and this issue happens every time
I do have a fix (I made this python function, and it is written rather inelegantly) but it's more of a band-aid than an actual solution (I would have to rerun it every so often when I encounter the page again):
def fixFrontmatter(mdfilepath, switch=False):
with open(mdfilepath, 'r',encoding='utf-8') as file:
lines = file.readlines()
if switch:
print("line length is ")
print(len(lines))
print(lines)
i = -1
removetoken = False
for line in lines:
if switch:
print(line)
i += 1
if (line == '---' or line == '---\n') and i < len(lines)-1:
if (lines[i+ 1] == '---' or lines[i+1] == '---\n'):
line = 'endit' + line
lines[i] = line
lines.remove(line)
removetoken = True
elif i == 2 and (line == '---' or line == '---\n') and removetoken == False: #for the case where it returns still but only as one dashed line, with banner as the top property
line = 'endit' + line
lines[i] = line
lines.remove(line)
if removetoken:
line = 'endit' + line
lines[i] = line
lines.remove(line)
removetoken = False
try:
if lines[0] != '---' and lines[0] != '---\n':
lines = ['---\n'] + lines
if lines[2] == '---' or lines[2] == '---\n':
lines[2] = 'endit' + lines[2]
lines.remove(lines[2])
except:
pass
with open(mdfilepath,'w',encoding='utf-8') as file:
file.writelines(lines)
This problem still occurs when I am opening vault on downloading it from git.