Skip to content

Commit

Permalink
support #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Benature committed Mar 27, 2024
1 parent a4f4c17 commit 566e31d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.1.3
- [feature] Provide option to not hide empty properties #5

## 0.1.2
- [fix] verbose console

Expand Down
50 changes: 36 additions & 14 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, debounce } from 'obsidian';

interface MetadataHiderSettings {
hideEmptyEntry: boolean;
hideEmptyEntryInSideDock: boolean;
propertiesVisible: string;
propertiesInvisible: string;
Expand All @@ -9,6 +10,7 @@ interface MetadataHiderSettings {
}

const DEFAULT_SETTINGS: MetadataHiderSettings = {
hideEmptyEntry: true,
hideEmptyEntryInSideDock: false,
propertiesVisible: "",
propertiesInvisible: "",
Expand Down Expand Up @@ -120,17 +122,21 @@ function genCSS(properties: string, cssPrefix: string, cssSuffix: string, parent

function genAllCSS(plugin: MetadataHider): string {
const s = plugin.settings;
const content: string[] = [
// Show all metadata when it is focused
`.metadata-container.is-active .metadata-property { display: flex !important; }`,
/* * Hide the metadata that is empty */
`.metadata-property:has(.metadata-property-value .mod-truncate:empty),`,
`.metadata-property:has(.metadata-property-value input.metadata-input[type="number"]:placeholder-shown),`,
`.metadata-property[data-property-type="text"]:has(input[type="date"]),`,
`.metadata-property:has(.metadata-property-value .multi-select-container > .multi-select-input:first-child) {`,
` display: none;`,
`}`,
];
let content: string[] = [];
if (s.hideEmptyEntry) {
content = content.concat([
// Show all metadata when it is focused
`.metadata-container.is-active .metadata-property { display: flex !important; }`,
/* * Hide the metadata that is empty */
`.metadata-property:has(.metadata-property-value .mod-truncate:empty),`,
`.metadata-property:has(.metadata-property-value input.metadata-input[type="number"]:placeholder-shown),`,
`.metadata-property[data-property-type="text"]:has(input[type="date"]),`,
`.metadata-property:has(.metadata-property-value .multi-select-container > .multi-select-input:first-child) {`,
` display: none;`,
`}`,
]);
}


if (!s.hideEmptyEntryInSideDock) {
content.push(`.mod-sidedock .metadata-property { display: flex !important; }`,)
Expand Down Expand Up @@ -177,17 +183,33 @@ class MetadataHiderSettingTab extends PluginSettingTab {
containerEl.empty();

new Setting(containerEl)
.setName({ en: 'Hide empty metadata properties also in side dock', zh: "侧边栏也隐藏值为空的文档属性(元数据)", "zh-TW": "側邊欄也隱藏空白文件屬性(元數據)" }[lang] as string)
.setName({ en: 'Hide empty metadata properties', zh: "隐藏值为空的文档属性(元数据)", "zh-TW": "隱藏空白文件屬性(元數據)" }[lang] as string)
.setDesc('')
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.hideEmptyEntryInSideDock)
.setValue(this.plugin.settings.hideEmptyEntry)
.onChange(async (value) => {
this.plugin.settings.hideEmptyEntryInSideDock = value;
this.plugin.settings.hideEmptyEntry = value;
await this.plugin.saveSettings();
this.plugin.debounceUpdateCSS();
this.display();
});
});
if (this.plugin.settings.hideEmptyEntry) {
new Setting(containerEl)
.setName({ en: 'Hide empty metadata properties also in side dock', zh: "侧边栏也隐藏值为空的文档属性(元数据)", "zh-TW": "側邊欄也隱藏空白文件屬性(元數據)" }[lang] as string)
.setDesc('')
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.hideEmptyEntryInSideDock)
.onChange(async (value) => {
this.plugin.settings.hideEmptyEntryInSideDock = value;
await this.plugin.saveSettings();
this.plugin.debounceUpdateCSS();
});
});
}


new Setting(containerEl)
.setName({ en: "Metadata properties that keep displaying", zh: "永远显示的文档属性(元数据)", "zh-TW": "永遠顯示的文件屬性(元數據)" }[lang] as string)
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "metadata-hider",
"name": "Metadata Hider",
"version": "0.1.2",
"version": "0.1.3",
"minAppVersion": "0.15.0",
"description": "Hide specific metadata property or if its value is empty.",
"author": "Benature",
Expand Down

0 comments on commit 566e31d

Please sign in to comment.