Skip to content

Commit

Permalink
feat: Adding support for folder note !
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Jun 1, 2022
1 parent 3b31cab commit cde9603
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
18 changes: 9 additions & 9 deletions mkdocsPublisher/githubInteraction/getFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,24 @@ export class GetFiles {
const frontMatter = this.metadataCache.getCache(
file.path
).frontmatter;
let filepath =
this.settings.folderDefaultName.length > 0
? this.settings.folderDefaultName + "/" + file.path
: file.path;
let filepath = this.settings.folderDefaultName.length > 0 ? this.settings.folderDefaultName + "/" + file.name : file.name;
if (frontMatter && frontMatter[shareKey] === true) {
if (this.settings.downloadedFolder === "yamlFrontmatter") {
if (frontMatter[this.settings.yamlFolderKey]) {
const category = frontMatter[this.settings.yamlFolderKey]
let parentCatFolder = category.split('/').at(-1)
parentCatFolder = parentCatFolder.length === 0 ? category.split('/').at(-2) : parentCatFolder
const fileName = this.settings.folderNote && parentCatFolder === file.name ? 'index.md' : file.name
filepath =
this.settings.rootFolder.length > 0
? this.settings.rootFolder + "/" + frontMatter[this.settings.yamlFolderKey] +
"/" + file.name : file.name;
"/" + fileName : fileName;
}
} else if (
this.settings.downloadedFolder === "fixedFolder"
this.settings.downloadedFolder === "obsidianPath"
) {
filepath =
this.settings.folderDefaultName.length > 0
? this.settings.folderDefaultName + "/" + file.name : file.name;
const fileName = file.name.replace('.md', '') === file.parent.name && this.settings.folderNote ? 'index.md' : file.name
filepath = this.settings.folderDefaultName.length > 0 ? this.settings.folderDefaultName + "/" + file.path.replace(file.name, fileName) : file.path.replace(file.name, fileName);
}
allFileWithPath.push(filepath);
}
Expand Down
10 changes: 7 additions & 3 deletions mkdocsPublisher/githubInteraction/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ export default class MkdocsPublish {
folderRoot = folderRoot + "/";
}
if (frontmatter[this.settings.yamlFolderKey]) {
const category = frontmatter[this.settings.yamlFolderKey]
let parentCatFolder = category.split('/').at(-1)
parentCatFolder = parentCatFolder.length === 0 ? category.split('/').at(-2) : parentCatFolder
const fileName = this.settings.folderNote && parentCatFolder === file.name ? 'index.md' : file.name
path =
folderRoot +
frontmatter[this.settings.yamlFolderKey] +
"/" +
file.name;
"/" + fileName;
}
} else if (this.settings.downloadedFolder === "obsidianPath") {
path = folderDefault + file.path;
const fileName = file.name.replace('.md', '') === file.parent.name && this.settings.folderNote ? 'index.md' : file.name
path = folderDefault + file.path.replace(file.name, fileName);
}
await this.uploadText(file.path, text, path, file.name, ref);
if (linkedImage.length > 0 && this.settings.transferEmbedded) {
Expand Down
12 changes: 12 additions & 0 deletions mkdocsPublisher/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ export class MkdocsSettingsTab extends PluginSettingTab {
});
});

new Setting(containerEl)
.setName('Folder note')
.setDesc('Rename files with the same name as their parent folder (or category) "index.md"')
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.folderNote)
.onChange(async (value)=>{
this.plugin.settings.folderNote=value;
await this.plugin.saveSettings();
})
})

containerEl.createEl('h1', { text: 'Plugin Settings' })
new Setting(containerEl)
.setName('Share Key')
Expand Down
2 changes: 2 additions & 0 deletions mkdocsPublisher/settings/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface MkdocsPublicationSettings {
defaultImageFolder: string;
autoCleanUp: boolean;
autoCleanUpExcluded: string;
folderNote: boolean;
}

export const DEFAULT_SETTINGS: MkdocsPublicationSettings = {
Expand All @@ -37,4 +38,5 @@ export const DEFAULT_SETTINGS: MkdocsPublicationSettings = {
defaultImageFolder: '',
autoCleanUp: false,
autoCleanUpExcluded: '',
folderNote: false
}
8 changes: 2 additions & 6 deletions mkdocsPublisher/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
App,
TFile,
Notice
} from 'obsidian'
import { MkdocsPublicationSettings } from '../settings/interface'
import {App, Notice, TFile} from 'obsidian'
import {MkdocsPublicationSettings} from '../settings/interface'
import MkdocsPublish from "../githubInteraction/upload";

function disablePublish (app: App, settings: MkdocsPublicationSettings, file:TFile) {
Expand Down

0 comments on commit cde9603

Please sign in to comment.