mirror of
https://github.com/Ellpeck/ObsidianJustSharePlease.git
synced 2024-11-23 02:48:34 +01:00
allow automatically updating shares
This commit is contained in:
parent
0bb5ae69b0
commit
07995d2a9a
5 changed files with 39 additions and 20 deletions
27
src/main.ts
27
src/main.ts
|
@ -72,6 +72,13 @@ export default class JustSharePleasePlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
}));
|
||||
this.registerEvent(this.app.vault.on("modify", f => {
|
||||
if (this.settings.autoUpdateShares && f instanceof TFile) {
|
||||
let shared = this.getSharedItem(f.path);
|
||||
if (shared)
|
||||
this.updateFile(shared, f, false);
|
||||
}
|
||||
}));
|
||||
|
||||
this.addCommand({
|
||||
id: "share",
|
||||
|
@ -177,12 +184,10 @@ export default class JustSharePleasePlugin extends Plugin {
|
|||
new Notice(`Successfully updated ${file.basename} on JSP`);
|
||||
return true;
|
||||
} catch (e) {
|
||||
if (notice) {
|
||||
new Notice(createFragment(f => {
|
||||
f.createSpan({text: `There was an error updating ${file.basename}: `});
|
||||
f.createEl("code", {text: e});
|
||||
}), 10000);
|
||||
}
|
||||
new Notice(createFragment(f => {
|
||||
f.createSpan({text: `There was an error updating ${file.basename}: `});
|
||||
f.createEl("code", {text: e});
|
||||
}), 10000);
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
|
@ -205,12 +210,10 @@ export default class JustSharePleasePlugin extends Plugin {
|
|||
new Notice(`Successfully deleted ${name} from JSP`);
|
||||
return true;
|
||||
} catch (e) {
|
||||
if (notice) {
|
||||
new Notice(createFragment(f => {
|
||||
f.createSpan({text: `There was an error deleting ${name}: `});
|
||||
f.createEl("code", {text: e});
|
||||
}), 10000);
|
||||
}
|
||||
new Notice(createFragment(f => {
|
||||
f.createSpan({text: `There was an error deleting ${name}: `});
|
||||
f.createEl("code", {text: e});
|
||||
}), 10000);
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ export class JSPSettingsTab extends PluginSettingTab {
|
|||
display(): void {
|
||||
this.containerEl.empty();
|
||||
this.containerEl.createEl("h2", {text: "Just Share Please Settings"});
|
||||
|
||||
new Setting(this.containerEl)
|
||||
.setName("Just Share Please Server")
|
||||
.setDesc(createFragment(f => {
|
||||
|
@ -31,7 +30,6 @@ export class JSPSettingsTab extends PluginSettingTab {
|
|||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(this.containerEl)
|
||||
.setName("Strip Frontmatter")
|
||||
.setDesc("Whether document frontmatter (also known as properties) should be removed from the uploaded share.")
|
||||
|
@ -42,7 +40,6 @@ export class JSPSettingsTab extends PluginSettingTab {
|
|||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(this.containerEl)
|
||||
.setName("Include Note Name")
|
||||
.setDesc("Whether the name of the shared note should be included in the share as a heading.")
|
||||
|
@ -53,7 +50,6 @@ export class JSPSettingsTab extends PluginSettingTab {
|
|||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(this.containerEl)
|
||||
.setName("Unshare Deleted Files")
|
||||
.setDesc("Whether shares of files should be removed automatically when they are deleted. Only supported when deleting from within Obsidian.")
|
||||
|
@ -64,6 +60,16 @@ export class JSPSettingsTab extends PluginSettingTab {
|
|||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
new Setting(this.containerEl)
|
||||
.setName("Automatically Update Shares")
|
||||
.setDesc("Whether a file's share should automatically be updated when the file is changed from within Obsidian.")
|
||||
.addToggle(t => {
|
||||
t.setValue(this.plugin.settings.autoUpdateShares);
|
||||
t.onChange(async v => {
|
||||
this.plugin.settings.autoUpdateShares = v;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
this.containerEl.createEl("hr");
|
||||
this.containerEl.createEl("p", {text: "If you like this plugin and want to support its development, you can do so through my website by clicking this fancy image!"});
|
||||
|
|
|
@ -3,10 +3,10 @@ export const defaultSettings: JSPSettings = {
|
|||
shared: [],
|
||||
stripFrontmatter: true,
|
||||
includeNoteName: true,
|
||||
unshareDeletedFiles: true
|
||||
unshareDeletedFiles: true,
|
||||
autoUpdateShares: false
|
||||
};
|
||||
|
||||
// TODO add a setting for auto-refreshing uploads when saving
|
||||
export interface JSPSettings {
|
||||
|
||||
url: string;
|
||||
|
@ -14,6 +14,7 @@ export interface JSPSettings {
|
|||
stripFrontmatter: boolean;
|
||||
includeNoteName: boolean;
|
||||
unshareDeletedFiles: boolean;
|
||||
autoUpdateShares: boolean;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,14 @@
|
|||
{
|
||||
"url": "http://localhost:8080",
|
||||
"shared": [],
|
||||
"shared": [
|
||||
{
|
||||
"id": "234df7b7",
|
||||
"password": "0ef1504bfe83cd9ca812434caa7aacf4",
|
||||
"path": "Cool Test Note.md"
|
||||
}
|
||||
],
|
||||
"stripFrontmatter": true,
|
||||
"includeNoteName": true,
|
||||
"unshareDeletedFiles": false
|
||||
"unshareDeletedFiles": false,
|
||||
"autoUpdateShares": false
|
||||
}
|
|
@ -24,6 +24,8 @@ $.ajax({
|
|||
|
||||
cool!!
|
||||
|
||||
blah blah i added and removed this
|
||||
|
||||
The following is $x^2 = 7$, but more complicated!
|
||||
$$
|
||||
x^2 + \sum_{i = 1}^{10000} x^2 \cdot 0 = 7
|
||||
|
|
Loading…
Reference in a new issue