Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
fix: fix setting issue after pull request
Browse files Browse the repository at this point in the history
re #32
  • Loading branch information
JYC333 committed Nov 14, 2023
1 parent e7f0312 commit 57df0b2
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 53 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## [2.1.3](https://github.com/JYC333/obsidian-file-structure-format/compare/2.1.0...2.1.3) (2023-11-14)


### Bug Fixes

* fix destination conflict ([5830926](https://github.com/JYC333/obsidian-file-structure-format/commit/583092624d1bc2c04ea2e7355ee256843eaa2508)), closes [#31](https://github.com/JYC333/obsidian-file-structure-format/issues/31)
* fix setting issue after pull request ([582b9fd](https://github.com/JYC333/obsidian-file-structure-format/commit/582b9fd3b5a6fe622e12ce4b4f4bfe01388a285d)), closes [#32](https://github.com/JYC333/obsidian-file-structure-format/issues/32)
* fix vault config bug ([60084b3](https://github.com/JYC333/obsidian-file-structure-format/commit/60084b3df9e0f27fcf2382c4b8ebeb08605ab38d)), closes [#30](https://github.com/JYC333/obsidian-file-structure-format/issues/30)



## [2.1.2](https://github.com/JYC333/obsidian-file-structure-format/compare/2.1.0...2.1.2) (2023-11-12)


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": "obsidian-attachment-name-formatting",
"name": "Attachment Name Formatting",
"version": "2.1.2",
"version": "2.1.3",
"minAppVersion": "0.12.0",
"description": "Obsidian plugin for formatting attachments name (filename attachmentType indexNumber.xxx)",
"author": "JYC333",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-attachment-name-formattion",
"version": "2.1.2",
"version": "2.1.3",
"description": "Obsidian plugin for formatting attachments name (filename attachmentType indexNumber.xxx)",
"main": "main.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const extensions: ExtensionList = {
export const DEFAULT_SETTINGS: ANFSettings = {
connectorOption: "Single",
connector: "_",
multipleConnectors: ["_", "_", "_"],
multipleConnectorsEnabled: [true, true, true],
multipleConnectors: ["_", "_", "_", "_"],
multipleConnectorsEnabled: [true, true, true, true],
enableImage: true,
imageExtensions: [true, true, true, true, true, true, true], // same amout with image extensions
image: "image",
Expand All @@ -27,6 +27,7 @@ export const DEFAULT_SETTINGS: ANFSettings = {
oneInMany: "Default",
enableAuto: true,
enableTime: false,
enablePathHash: false,
enableExcludeFileName: false,
excludedFolders: [],
subfolders: ["", "", "", ""],
Expand All @@ -38,7 +39,6 @@ export const DEFAULT_SETTINGS: ANFSettings = {
copyPathMode: "Relative",
usingLog: false,
logPath: "/",
appendPathHash: false,
};

export const ATTACHMENT_TYPE = ["image", "audio", "video", "pdf"];
48 changes: 33 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export default class AttachmentNameFormatting extends Plugin {
baseNameComponent.push(date_String);
}

if (this.settings.appendPathHash) {
if (this.settings.enablePathHash) {
const appendPathHashValue = crypto
.createHash("md5")
.update(file.parent.path)
Expand All @@ -419,21 +419,39 @@ export default class AttachmentNameFormatting extends Plugin {
let newName = "";
if (this.settings.connectorOption === "Multiple") {
newName += baseNameComponent[0];
const connectorShift = this.settings
.enableExcludeFileName
? 0
: 1;

let optionIndex: number[] = [1];

if (
this.settings.enableTime &&
!this.settings.enablePathHash
) {
optionIndex.push(2);
} else if (
!this.settings.enableTime &&
this.settings.enablePathHash
) {
optionIndex.push(3);
} else if (
this.settings.enableTime &&
this.settings.enablePathHash
) {
optionIndex.push(2, 3);
}

if (!this.settings.enableExcludeFileName) {
optionIndex.unshift(0);
}

let connectors = [];
for (let i of optionIndex) {
connectors.push(
this.settings.multipleConnectors[i]
);
}

for (let i = 1; i < baseNameComponent.length; i++) {
if (
this.settings.multipleConnectorsEnabled[
i - connectorShift
]
) {
newName +=
this.settings.multipleConnectors[
i - connectorShift
];
}
newName += connectors[i - 1];
newName += baseNameComponent[i];
}
newName += "." + attachmentFile.extension;
Expand Down
41 changes: 26 additions & 15 deletions src/modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ export class MultiConnectorModal extends Modal {
}

checkValidity(value: string) {
const fileNamepatn = /\||<|>|\?|\*|:|\/|\\|#|\^|\[|\]"/;
const fileNamepatn = /\||<|>|\?|\*|:|\/|\\|#|\^|\[|\]"|%/;
if (fileNamepatn.test(value)) {
new WarningModal(
this.app,
"Invalid character for filename, will remove the character!"
).open();
value = value.replace(fileNamepatn, "");
this.plugin.settings.multipleConnectors[0] = value;
this.onClose();
this.onOpen();
}
return value;
}

onOpen() {
Expand All @@ -108,26 +108,37 @@ export class MultiConnectorModal extends Modal {
text: `Connectors`,
});

let optionLength;

const optionNames = [
"File name and attachment type",
"Attachment type and index number",
"Index number and time",
"Connector before attachment type",
"Connector before index number",
"Connector before time suffix",
"Connector before path hash",
];

let optionIndex: number[] = [1];

if (
this.plugin.settings.enableExcludeFileName ||
this.plugin.settings.enableTime
this.plugin.settings.enableTime &&
!this.plugin.settings.enablePathHash
) {
optionIndex.push(2);
} else if (
!this.plugin.settings.enableTime &&
this.plugin.settings.enablePathHash
) {
optionLength = 3;
} else {
optionLength = 2;
optionIndex.push(3);
} else if (
this.plugin.settings.enableTime &&
this.plugin.settings.enablePathHash
) {
optionIndex.push(2, 3);
}

const startPonit = this.plugin.settings.enableExcludeFileName ? 1 : 0;
if (!this.plugin.settings.enableExcludeFileName) {
optionIndex.unshift(0);
}

for (let i = startPonit; i < optionLength; i++) {
for (let i of optionIndex) {
const connectorSetting = new Setting(contentEl).setName(
optionNames[i]
);
Expand All @@ -141,7 +152,7 @@ export class MultiConnectorModal extends Modal {
: this.plugin.settings.multipleConnectors[i]
)
.onChange(async (value) => {
this.checkValidity(value);
value = this.checkValidity(value);
this.plugin.settings.multipleConnectors[i] =
value === ""
? DEFAULT_SETTINGS.multipleConnectors[i]
Expand Down
47 changes: 31 additions & 16 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class ANFSettingTab extends PluginSettingTab {
] as string)
)
.onChange(async (value) => {
const fileNamepatn = /\||<|>|\?|\*|:|\/|\\|"/;
const fileNamepatn = /\||<|>|\?|\*|:|\/|\\|#|\^|\[|\]"|%/;
if (fileNamepatn.test(value)) {
new WarningModal(
this.app,
Expand Down Expand Up @@ -211,50 +211,65 @@ export class ANFSettingTab extends PluginSettingTab {
});

new Setting(containerEl)
.setName("Add path hash at end of attachment name")
.setName("Automatic formatting")
.setDesc(
"For uniqueness in attachment names if there are note files with the same name (but at different levels)"
"Automatic formatting the attachments' name when changing note content"
)
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.appendPathHash)
.setValue(this.plugin.settings.enableAuto)
.onChange(async (value) => {
this.plugin.settings.appendPathHash = value;
this.plugin.settings.enableAuto = value;
await this.plugin.saveSettings();
});
});

new Setting(containerEl)
.setName("Automatic formatting")
.setName("Add modify time after index")
.setDesc(
"Automatic formatting the attachments' name when changing note content"
"Add modify time after index to track the change time in file name"
)
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.enableAuto)
.setValue(this.plugin.settings.enableTime)
.onChange(async (value) => {
this.plugin.settings.enableAuto = value;
if (
this.plugin.settings.enableExcludeFileName &&
!this.plugin.settings.enablePathHash
) {
new WarningModal(
app,
"At least enable time suffix or path hash when enable exclude the note name!"
).open();
this.plugin.settings.enableTime = true;
} else {
this.plugin.settings.enableTime = value;
}
await this.plugin.saveSettings();
this.display();
});
});

new Setting(containerEl)
.setName("Add modify time after index")
.setName("Add path hash at end of attachment name")
.setDesc(
"Add modify time after index to track the change time in file name"
"For uniqueness in attachment names if there are note files with the same name (but at different levels)"
)
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.enableTime)
.setValue(this.plugin.settings.enablePathHash)
.onChange(async (value) => {
if (this.plugin.settings.enableExcludeFileName) {
if (
this.plugin.settings.enableExcludeFileName &&
!this.plugin.settings.enableTime
) {
new WarningModal(
app,
"Cannot exclude time suffix when enable exclude the note name!"
"At least enable time suffix or path hash when enable exclude the note name!"
).open();
this.plugin.settings.enableTime = true;
this.plugin.settings.enablePathHash = true;
} else {
this.plugin.settings.enableTime = value;
this.plugin.settings.enablePathHash = value;
}
await this.plugin.saveSettings();
this.display();
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface ANFSettings {
oneInMany: string;
enableAuto: boolean;
enableTime: boolean;
enablePathHash: boolean;
enableExcludeFileName: boolean;
excludedFolders: string[];
subfolders: string[];
Expand All @@ -33,7 +34,6 @@ export interface ANFSettings {
copyPathMode: string;
usingLog: boolean;
logPath: string;
appendPathHash: boolean;
}

export interface ExtensionList {
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
"2.0.0": "0.12.0",
"2.1.0": "0.12.0",
"2.1.1": "0.12.0",
"2.1.2": "0.12.0"
"2.1.2": "0.12.0",
"2.1.3": "0.12.0"
}

0 comments on commit 57df0b2

Please sign in to comment.