Skip to content

Commit

Permalink
fix(banner_header): separate settings for frontmatter key & default name
Browse files Browse the repository at this point in the history
Also add info about the needing to reload the file to see the changes when editing the settings/Property
  • Loading branch information
Mara-Li committed Sep 22, 2023
1 parent dbcab0f commit 9a64100
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
16 changes: 9 additions & 7 deletions src/banner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,21 @@ export const getHeaderText = (header: string[] | string | null | undefined,
settings: BannerSettings):
string | undefined => {
const frontmatter = plug.app.metadataCache.getFileCache(file)?.frontmatter;
if (settings.headerPropertyKey && settings.headerByDefault && frontmatter) {
const key = settings.headerPropertyKey;
return getFrontMatterKey(key, frontmatter, file.basename);
const defautValue = settings.headerByDefault ? file.basename : undefined;
if (header === undefined) {
if (settings.headerPropertyKey) {
const key = settings.headerPropertyKey;
const defautValue = settings.headerByDefault ? file.basename : undefined;
return getFrontMatterKey(key, frontmatter, defautValue);
} if (settings.headerByDefault) return file.basename;
return undefined;
}
if (settings.headerByDefault && header === undefined) return file.basename;
if (header === undefined) return undefined;
if (header === null) return file.basename;
/** In list it is useful to have fallback. ie if a key don't exist, use the second, etc.
* If no key exist, it returns the header join by space
*/
if (Array.isArray(header)) {
if (!frontmatter) return header.join(' ');
if (!frontmatter) return defautValue;
for (const h of header) {
const propertyKey = h.match(/\{{(.*)\}}/)?.[1];
const frontmatterKey = getFrontMatterKey(propertyKey, frontmatter);
Expand All @@ -160,7 +163,6 @@ export const getHeaderText = (header: string[] | string | null | undefined,
else if (keyName === 'file') header = header.replace(property, file.basename);
}
}
console.log('HEADER', header);
return header;

};
Expand Down
17 changes: 8 additions & 9 deletions src/settings/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,14 @@
If a banner has no header, display the filename as the header instead.
</span>
</ToggleSetting>
<Depends on="headerByDefault">
<InputSetting key="headerPropertyKey" numOrStr>
<span slot="name">Property as header</span>
<span slot="description">
Allow to use the value of a Property as the header instead of the filename.
Leave it empty to disable this feature.
</span>
</InputSetting>
</Depends>
<InputSetting key="headerPropertyKey" numOrStr>
<span slot="name">Property as header</span>
<span slot="description">
Allow to use the value of a Property as the header instead of the filename.
Leave it empty to disable this feature.
Note that you will need to reload the file to see the changes.
</span>
</InputSetting>

<!-- Banner Icons -->
<Header
Expand Down

0 comments on commit 9a64100

Please sign in to comment.