Skip to content

Commit

Permalink
support hiding in all properties #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Benature committed Mar 30, 2024
1 parent 109b0ce commit 297aa87
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 10 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ jobs:
asset_path: ./manifest.json
asset_name: manifest.json
asset_content_type: application/json
# - name: Upload styles.css
# id: upload-styles
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: ./styles.css
# asset_name: styles.css
# asset_content_type: text/javascript
- name: Upload styles.css
id: upload-styles
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./styles.css
asset_name: styles.css
asset_content_type: text/javascript
45 changes: 45 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,72 @@
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, debounce } from 'obsidian';

interface entryHideSettings {
tableInactive: boolean; // hide in .mod-root when .metadata-container is inactive
tableActive: boolean; // hide in .mod-root when .metadata-container is active
fileProperties: boolean;
allProperties: boolean;
}
interface entrySettings {
name: string;
hide: entryHideSettings;
}
interface MetadataHiderSettings {
autoFold: boolean;
hideEmptyEntry: boolean;
hideEmptyEntryInSideDock: boolean;
// hidePropertiesInvisibleInAllProperties: boolean;
propertiesVisible: string;
propertiesInvisible: string;
propertiesInvisibleAlways: string;
propertyHideAll: string;
entries: entrySettings[];
}

const DEFAULT_SETTINGS: MetadataHiderSettings = {
autoFold: false,
hideEmptyEntry: true,
hideEmptyEntryInSideDock: false,
// hidePropertiesInvisibleInAllProperties: false,
propertiesVisible: "",
propertiesInvisible: "",
propertiesInvisibleAlways: "",
propertyHideAll: "hide",
entries: [],
}



export default class MetadataHider extends Plugin {
settings: MetadataHiderSettings;
styleTag: HTMLStyleElement;

isMetadataFocused: boolean;

hideInAllProperties() {
const metadataElement = document.querySelector('.workspace-leaf-content[data-type="all-properties"] .view-content');
if (metadataElement == null) { return; }

let propertiesInvisible = string2list(this.settings.propertiesInvisible);

const items = metadataElement.querySelectorAll('.tree-item');
items.forEach(item => {
const inner = item.querySelector('.tree-item-inner');
if (inner && inner.textContent && propertiesInvisible.includes(inner.textContent)) {
item.classList.add('mh-hide')
}
});
}




async onload() {
await this.loadSettings();
this.addSettingTab(new MetadataHiderSettingTab(this.app, this));
this.updateCSS();

this.hideInAllProperties();

this.registerDomEvent(document, 'focusin', (evt: MouseEvent) => {
// console.log('focusin', evt);
const target = evt.target;
Expand Down Expand Up @@ -114,7 +149,13 @@ export default class MetadataHider extends Plugin {
await this.saveData(this.settings);
}

upgradeSettingsToVersion1() { // upgrade settings from version 0.x to 1.x

}
}

function string2list(properties: string): string[] {
return properties.replace(/\n|^\s*,|,\s*$/g, "").replace(/,,+/g, ",").split(",").map(p => p.trim());
}

function genCSS(properties: string, cssPrefix: string, cssSuffix: string, parentSelector: string = ""): string {
Expand Down Expand Up @@ -246,6 +287,10 @@ class MetadataHiderSettingTab extends PluginSettingTab {
this.plugin.debounceUpdateCSS();
})
);




new Setting(containerEl)
.setName({ en: "Metadata properties always to hide", zh: "永远隐藏的文档属性(元数据)", "zh-TW": "永遠隱藏的文件屬性(元數據)" }[lang] as string)
.setDesc({ en: "Metadata properties will always hide even if their value are not empty or the metadata properties table is focused. Metadata property keys are separated by comma (`,`)", zh: "英文逗号分隔(`,`)。如:“tags, aliases”", "zh-TW": "以逗號分隔(`,`)" }[lang] as string)
Expand Down
15 changes: 15 additions & 0 deletions manifest-beta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": "metadata-hider",
"name": "Metadata Hider",
"version": "0.2.0-b1",
"minAppVersion": "0.15.0",
"description": "Hide specific metadata property or if its value is empty.",
"author": "Benature",
"authorUrl": "https://github.com/Benature",
"fundingUrl": {
"Buy Me a Coffee": "https://www.buymeacoffee.com/benature",
"爱发电": "https://afdian.net/a/Benature-K",
"微信/支付宝": "https://s2.loli.net/2024/01/30/jQ9fTSyBxvXRoOM.png"
},
"isDesktopOnly": false
}
5 changes: 5 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.workspace-leaf-content[data-type="all-properties"]
.view-content
.tree-item.mh-hide {
display: none;
}

0 comments on commit 297aa87

Please sign in to comment.