Skip to content

Commit

Permalink
fix: Trim whitespace for excluded folder checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Apr 11, 2022
1 parent 80de815 commit 2a44ab9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export default class mkdocsPublication extends Plugin {

this.registerEvent(
this.app.workspace.on('file-menu', (menu, file:TFile) =>{
if (!disablePublish(this.app, this.settings, file)){
if (!disablePublish(this.app, this.settings, file) || !this.settings.fileMenu){
return false;
}
menu.addSeparator();
menu.addItem((item)=>{
item.setTitle("Share " + file.name + " on Mkdocs")
item.setTitle("Share " + file.basename + " with Mkdocs Publication")
.setIcon("share")
.onClick(async()=>{
try {
Expand Down
5 changes: 3 additions & 2 deletions src/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export default class MkdocsPublish {

checkExcludedFolder(file: TFile) {
const excluded_folder = this.settings.ExcludedFolder.split("/");
for (const folder of excluded_folder) {
if (file.path.contains(folder)) {
for (let i = 0; i < excluded_folder.length; i++) {
if (file.path.contains(excluded_folder[i].trim())) {
return true;
}
}
Expand All @@ -70,6 +70,7 @@ export default class MkdocsPublish {
async publish(file: TFile, one_file: boolean = false) {
const sharedkey = this.settings.shareKey;
const frontmatter = this.metadataCache.getCache(file.path).frontmatter;
this.checkExcludedFolder(file)
if (!frontmatter || !frontmatter[sharedkey] || this.checkExcludedFolder(file)) {
return false;
}
Expand Down
13 changes: 13 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface mkdocsPublicationSettings {
GhToken: string;
shareKey: string;
ExcludedFolder: string;
fileMenu: boolean;
}

export const DEFAULT_SETTINGS: mkdocsPublicationSettings = {
Expand All @@ -15,6 +16,7 @@ export const DEFAULT_SETTINGS: mkdocsPublicationSettings = {
GhToken: "",
shareKey: "share",
ExcludedFolder: "",
fileMenu: false,
};

export class mkdocsSettingsTab extends PluginSettingTab {
Expand Down Expand Up @@ -96,6 +98,17 @@ export class mkdocsSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName("File Menu")
.setDesc('Add an sharing commands in the file menu')
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.fileMenu)
.onChange(async(value)=>{
this.plugin.settings.fileMenu = value;
await this.plugin.saveSettings();
})
);

}
}
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function disablePublish(app: App, settings: mkdocsPublicationSettings, file:TFil
return false;
} else if (folder_list.length > 0) {
for (let i = 0; i < folder_list.length; i++) {
if (file.path.contains(folder_list[i])) {
if (file.path.contains(folder_list[i].trim())) {
return false;
}
}
Expand Down

0 comments on commit 2a44ab9

Please sign in to comment.