Skip to content

Commit

Permalink
feat(List/Matrix View): ✨ Option to only show the first alias (Fix #237)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jan 9, 2022
1 parent 53b32eb commit aa0be01
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
14 changes: 12 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21145,6 +21145,7 @@ const DEFAULT_SETTINGS = {
regexNoteField: "",
rlLeaf: true,
showAllPathsIfNoneToIndexNote: false,
showAllAliases: true,
showBCs: true,
showBCsInEditLPMode: false,
showRefreshNotice: true,
Expand Down Expand Up @@ -24893,15 +24894,16 @@ class MatrixView extends require$$0.ItemView {
}
getAlt(node) {
var _a;
const { altLinkFields } = this.plugin.settings;
const { altLinkFields, showAllAliases } = this.plugin.settings;
if (altLinkFields.length) {
const file = this.app.metadataCache.getFirstLinkpathDest(node, "");
if (file) {
const metadata = this.app.metadataCache.getFileCache(file);
for (const altField of altLinkFields) {
const value = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.frontmatter) === null || _a === void 0 ? void 0 : _a[altField];
const arr = typeof value === "string" ? splitAndTrim(value) : value;
if (value)
return value;
return showAllAliases ? arr.join(", ") : arr[0];
}
}
}
Expand Down Expand Up @@ -25183,6 +25185,14 @@ class BCSettingTab extends require$$0.PluginSettingTab {
await plugin.saveSettings();
};
});
new require$$0.Setting(generalDetails)
.setName("Only show first alias")
.setDesc("If a note has an alias (using the fields in the setting above), should only the first one be shown?")
.addToggle((toggle) => toggle.setValue(!settings.showAllAliases).onChange(async (value) => {
settings.showAllAliases = !value;
await plugin.saveSettings();
await plugin.refreshIndex();
}));
new require$$0.Setting(generalDetails)
.setName("Use yaml or inline fields for hierarchy data")
.setDesc("If enabled, Breadcrumbs will make it's hierarchy using yaml fields, and inline fields (if you have Dataview enabled).\nIf this is disabled, it will only use Juggl links for it's metadata (See below).")
Expand Down
13 changes: 13 additions & 0 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ export class BCSettingTab extends PluginSettingTab {
};
});

new Setting(generalDetails)
.setName("Only show first alias")
.setDesc(
"If a note has an alias (using the fields in the setting above), should only the first one be shown?"
)
.addToggle((toggle) =>
toggle.setValue(!settings.showAllAliases).onChange(async (value) => {
settings.showAllAliases = !value;
await plugin.saveSettings();
await plugin.refreshIndex();
})
);

new Setting(generalDetails)
.setName("Use yaml or inline fields for hierarchy data")
.setDesc(
Expand Down
9 changes: 6 additions & 3 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
UserHier,
} from "./interfaces";
import type BCPlugin from "./main";
import { getRealnImplied, linkClass } from "./sharedFunctions";
import { getRealnImplied, linkClass, splitAndTrim } from "./sharedFunctions";

export default class MatrixView extends ItemView {
private plugin: BCPlugin;
Expand Down Expand Up @@ -64,14 +64,17 @@ export default class MatrixView extends ItemView {
}

getAlt(node: string): string | null {
const { altLinkFields } = this.plugin.settings;
const { altLinkFields, showAllAliases } = this.plugin.settings;
if (altLinkFields.length) {
const file = this.app.metadataCache.getFirstLinkpathDest(node, "");
if (file) {
const metadata = this.app.metadataCache.getFileCache(file);
for (const altField of altLinkFields) {
const value = metadata?.frontmatter?.[altField];
if (value) return value;

const arr: string[] =
typeof value === "string" ? splitAndTrim(value) : value;
if (value) return showAllAliases ? arr.join(", ") : arr[0];
}
}
} else return null;
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export const DEFAULT_SETTINGS: BCSettings = {
regexNoteField: "",
rlLeaf: true,
showAllPathsIfNoneToIndexNote: false,
showAllAliases: true,
showBCs: true,
showBCsInEditLPMode: false,
showRefreshNotice: true,
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface BCSettings {
refreshOnNoteChange: boolean;
respectReadableLineLength: boolean;
showAllPathsIfNoneToIndexNote: boolean;
showAllAliases: boolean;
showNameOrType: boolean;
showRelationType: boolean;
showWriteAllBCsCmd: boolean;
Expand Down

0 comments on commit aa0be01

Please sign in to comment.