ignore paths by regexgit add .

This commit is contained in:
fyears 2024-01-04 00:26:02 +08:00
parent 9e4d3826fd
commit 6a651b844f
5 changed files with 67 additions and 9 deletions

View File

@ -26,6 +26,7 @@ This is yet another unofficial sync plugin for Obsidian. If you like it or find
- **[End-to-end encryption](./docs/encryption.md) supported.** Files would be encrypted using openssl format before being sent to the cloud **if** user specify a password.
- **Scheduled auto sync supported.** You can also manually trigger the sync using sidebar ribbon, or using the command from the command palette (or even bind the hot key combination to the command then press the hot key combination).
- **[Minimal Intrusive](./docs/minimal_intrusive_design.md).**
- **Skip Large files and skip paths by custom regex conditions!
- **Fully open source under [Apache-2.0 License](./LICENSE).**
- **[Sync Algorithm open](./docs/sync_algorithm_v2.md) for discussion.**

View File

@ -85,7 +85,7 @@ const DEFAULT_SETTINGS: RemotelySavePluginSettings = {
lang: "auto",
logToDB: false,
skipSizeLargerThan: -1,
ignorePaths: [".obsidian/workspace.json", ".obsidian/workspace-mobile.json", ".obsidian/community-plugins.json"],
ignorePaths: [],
};
interface OAuth2Info {
@ -795,6 +795,9 @@ export default class RemotelySavePlugin extends Plugin {
if (this.settings.s3.forcePathStyle === undefined) {
this.settings.s3.forcePathStyle = false;
}
if (this.settings.ignorePaths === undefined) {
this.settings.ignorePaths = [];
}
}
async checkIfPresetRulesFollowed() {

View File

@ -1599,13 +1599,18 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
new Setting(basicDiv)
.setName(t("settings_ignorepaths"))
.setDesc(t("settings_ignorepaths_desc"))
.setClass("ignorepaths-settings")
.addTextArea((textArea) => {
textArea
.setValue(`${this.plugin.settings.ignorePaths.join("\n")}`)
.onChange(async (value) => {
this.plugin.settings.ignorePaths = value.split("\n");
this.plugin.settings.ignorePaths = value.trim().split("\n");
await this.plugin.saveSettings();
});
textArea.inputEl.rows = 10;
textArea.inputEl.addClass("ignorepaths-textarea");
});
//////////////////////////////////////////////////

View File

@ -7,6 +7,7 @@ import {
} from "obsidian";
import AggregateError from "aggregate-error";
import PQueue from "p-queue";
import XRegExp from "xregexp";
import type {
RemoteItem,
SyncTriggerSourceType,
@ -296,8 +297,12 @@ const isSkipItem = (
configDir: string,
ignorePaths: string[]
) => {
if (ignorePaths.includes(key)) {
return true;
if (ignorePaths !== undefined && ignorePaths.length > 0) {
for (const r of ignorePaths) {
if (XRegExp(r, "A").test(key)) {
return true;
}
}
}
if (syncConfigDir && isInsideObsFolder(key, configDir)) {
return false;
@ -327,7 +332,15 @@ const ensembleMixedStates = async (
for (const r of remoteStates) {
const key = r.key;
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) {
if (
isSkipItem(
key,
syncConfigDir,
syncUnderscoreItems,
configDir,
ignorePaths
)
) {
continue;
}
results[key] = r;
@ -366,7 +379,15 @@ const ensembleMixedStates = async (
throw Error(`unexpected ${entry}`);
}
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) {
if (
isSkipItem(
key,
syncConfigDir,
syncUnderscoreItems,
configDir,
ignorePaths
)
) {
continue;
}
@ -400,7 +421,15 @@ const ensembleMixedStates = async (
password === "" ? undefined : getSizeFromOrigToEnc(entry.size),
};
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) {
if (
isSkipItem(
key,
syncConfigDir,
syncUnderscoreItems,
configDir,
ignorePaths
)
) {
continue;
}
@ -426,7 +455,15 @@ const ensembleMixedStates = async (
deltimeRemoteFmt: unixTimeToStr(entry.actionWhen),
} as FileOrFolderMixedState;
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) {
if (
isSkipItem(
key,
syncConfigDir,
syncUnderscoreItems,
configDir,
ignorePaths
)
) {
continue;
}
@ -454,7 +491,15 @@ const ensembleMixedStates = async (
throw Error(`unexpected ${entry}`);
}
if (isSkipItem(key, syncConfigDir, syncUnderscoreItems, configDir, ignorePaths)) {
if (
isSkipItem(
key,
syncConfigDir,
syncUnderscoreItems,
configDir,
ignorePaths
)
) {
continue;
}

View File

@ -61,3 +61,7 @@
width: 350px;
height: 350px;
}
.ignorepaths-textarea {
font-family: monospace;
}