Skip to content

Commit

Permalink
feat: adding obsidian path option
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed May 23, 2022
1 parent 4460526 commit 7714ae4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
54 changes: 29 additions & 25 deletions mkdocsPublisher/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export class MkdocsSettingsTab extends PluginSettingTab {
dropDown
.addOptions({
fixedFolder : 'Fixed Folder',
yamlFrontmatter: 'YAML frontmatter'
yamlFrontmatter: 'YAML frontmatter',
obsidianPath: 'Obsidian Path'
})
.setValue(this.plugin.settings.downloadedFolder)
.onChange(async(value: string)=>{
Expand All @@ -140,35 +141,37 @@ export class MkdocsSettingsTab extends PluginSettingTab {
.setPlaceholder('docs')
.setValue(this.plugin.settings.folderDefaultName)
.onChange(async (value) => {
this.plugin.settings.folderDefaultName = value.replace('/', '');
this.plugin.settings.folderDefaultName = value.replace(/\/$/, '');
await this.plugin.saveSettings();
});
});

const frontmatterKeySettings = new Setting(this.containerEl)
.setName('Frontmatter key')
.setDesc('Set the key where to get the value of the folder')
.addText((text) => {
text
.setPlaceholder('category')
.setValue(this.plugin.settings.yamlFolderKey)
.onChange(async (value) => {
this.plugin.settings.yamlFolderKey = value.trim();
await this.plugin.saveSettings();
});
});
const rootFolderSettings = new Setting(this.containerEl)
.setName('Root folder')
.setDesc('Append this path to the folder set by the frontmatter key.')
.addText((text)=>{
text
.setPlaceholder('docs')
.setValue(this.plugin.settings.rootFolder)
.onChange(async(value)=>{
this.plugin.settings.rootFolder =value.replace('/', '');
await this.plugin.saveSettings();
.setName('Frontmatter key')
.setClass('mdkocs-settings-tab')
.setDesc('Set the key where to get the value of the folder')
.addText((text) => {
text
.setPlaceholder('category')
.setValue(this.plugin.settings.yamlFolderKey)
.onChange(async (value) => {
this.plugin.settings.yamlFolderKey = value.trim();
await this.plugin.saveSettings();
});
});
const rootFolderSettings = new Setting(this.containerEl)
.setName('Root folder')
.setClass('mdkocs-settings-tab')
.setDesc('Append this path to the folder set by the frontmatter key.')
.addText((text)=>{
text
.setPlaceholder('docs')
.setValue(this.plugin.settings.rootFolder)
.onChange(async(value)=>{
this.plugin.settings.rootFolder =value.replace(/\/$/, '');
await this.plugin.saveSettings();
});
});

if (this.plugin.settings.downloadedFolder == 'yamlFrontmatter') {
showSettings(frontmatterKeySettings);
Expand All @@ -187,7 +190,8 @@ export class MkdocsSettingsTab extends PluginSettingTab {
.setPlaceholder('ci')
.setValue(this.plugin.settings.workflowName)
.onChange(async(value)=> {
this.plugin.settings.workflowName = value.trim().replace('.yml', '') + '.yml'
value = value.length>0? value.trim().replace('.yml', '') + '.yml' : value;
this.plugin.settings.workflowName = value;
await this.plugin.saveSettings();
});
});
Expand All @@ -214,7 +218,7 @@ export class MkdocsSettingsTab extends PluginSettingTab {
.setPlaceholder('docs/images')
.setValue(this.plugin.settings.defaultImageFolder)
.onChange(async(value)=>{
this.plugin.settings.defaultImageFolder = value.replace('/', '');
this.plugin.settings.defaultImageFolder = value.replace(/\/$/, '');
await this.plugin.saveSettings();
});
});
Expand Down
9 changes: 7 additions & 2 deletions mkdocsPublisher/utils/publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ export default class MkdocsPublish {
try {
const text = await this.vault.cachedRead(file);
const linkedImage = this.getLinkedImage(file);
let path = this.settings.folderDefaultName + '/' + file.name;
let folderDefault = this.settings.folderDefaultName
if (folderDefault.length > 0) {
folderDefault = folderDefault + '/'
}
let path = folderDefault + file.name;
if (this.settings.downloadedFolder === 'yamlFrontmatter') {
let folderRoot = this.settings.rootFolder;
if (folderRoot.length > 0) {
Expand All @@ -83,8 +87,9 @@ export default class MkdocsPublish {
if (frontmatter[this.settings.yamlFolderKey]) {
path = folderRoot + frontmatter[this.settings.yamlFolderKey] + '/' + file.name;
}
} else if (this.settings.downloadedFolder === 'obsidianPath') {
path = folderDefault + file.path;
}
console.log(path, this.settings.downloadedFolder, this.settings.yamlFolderKey)
await this.uploadText(file.path, text, path, file.name);
if (linkedImage.length > 0 && this.settings.transfertEmbeded) {
for (const image of linkedImage) {
Expand Down

0 comments on commit 7714ae4

Please sign in to comment.