Skip to content

Commit

Permalink
feat: Universalize the plugin
Browse files Browse the repository at this point in the history
Allowing the plugin to work with every obsidian publish alternative that use github

BREAKING CHANGE: Remove the workflow update
  • Loading branch information
Mara-Li committed May 23, 2022
1 parent b0f0861 commit 837ef71
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 137 deletions.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "obsidian-mkdocs-publisher",
"name": "Mkdocs Publisher",
"name": "Github Publisher",
"version": "2.4.0",
"minAppVersion": "0.14.5",
"description": "Obsidian's Mkdocs Publisher is an association between a github actions and a Material mkdocs template to get a personal wiki site based on your Obsidian Vault.",
"description": "Github Publisher is a plugin that help you to send file in a configured Github Repository, based on a frontmatter entry state.",
"author": "Mara-Li",
"authorUrl": "https://github.com/Mara-Li",
"isDesktopOnly": false
Expand Down
26 changes: 2 additions & 24 deletions mkdocsPublisher/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ export default class MkdocsPublication extends Plugin {
);
// upload list of published files in Source
const publishedFilesText = JSON.stringify(publishedFiles).toString();
const publishedJsonPath = this.settings.folderDefaultName + '/vault_published.json'
await publish.uploadText(
"vault_published.json",
publishedFilesText,
"vault_published.json"
publishedJsonPath
);
for (
let files = 0;
Expand Down Expand Up @@ -215,29 +216,6 @@ export default class MkdocsPublication extends Plugin {
}
},
});
this.addCommand({
id: "obs2mk-update-settings",
name: "Update settings workflow",
callback: async () => {
try {
const { vault, metadataCache } = this.app;
const publish = new MkdocsPublish(
vault,
metadataCache,
this.settings
);
const successUpdate = await publish.updateSettings();
if (successUpdate) {
new Notice("Successfully updated " + this.settings.githubRepo + "settings.");
}
} catch (e) {
console.error(e);
new Notice(
"Unable to update settings, something went wrong."
);
}
},
});
}

onunload() {
Expand Down
211 changes: 149 additions & 62 deletions mkdocsPublisher/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ export interface MkdocsPublicationSettings {
ExcludedFolder: string;
fileMenu: boolean;
editorMenu: boolean;
categoryKey: string;
categoryDefault: string;
indexFolder: string;
downloadedFolder: string;
folderDefaultName: string;
yamlFolderKey: string;
rootFolder: string;
workflowName: string;
transfertEmbeded: boolean;
defaultImageFolder: string;
}

export const DEFAULT_SETTINGS: MkdocsPublicationSettings = {
Expand All @@ -22,9 +26,25 @@ export const DEFAULT_SETTINGS: MkdocsPublicationSettings = {
ExcludedFolder: '',
fileMenu: false,
editorMenu: false,
categoryKey: 'category',
categoryDefault: 'notes',
indexFolder: '(i)'
downloadedFolder: 'fixedFolder',
folderDefaultName: '',
yamlFolderKey: '',
rootFolder: '',
workflowName: '',
transfertEmbeded: true,
defaultImageFolder: '',
}

function showSettings(containerEl: Setting) {
containerEl.descEl.show();
containerEl.nameEl.show();
containerEl.controlEl.show();
}

function hideSettings(containerEl: Setting) {
containerEl.descEl.hide();
containerEl.nameEl.hide();
containerEl.controlEl.hide();
}

export class MkdocsSettingsTab extends PluginSettingTab {
Expand All @@ -37,8 +57,9 @@ export class MkdocsSettingsTab extends PluginSettingTab {

display(): void {
const {containerEl} = this
containerEl.empty()
containerEl.createEl('h1', {text: 'Mkdocs Publication Settings'})
containerEl.empty();
containerEl.createEl('h1', {text: 'Github Configuration'})
containerEl.createEl('h2', {text: 'Github settings'})
new Setting(containerEl)
.setName('Repo Name')
.setDesc('The name of the repository where you store your blog.')
Expand Down Expand Up @@ -79,11 +100,128 @@ export class MkdocsSettingsTab extends PluginSettingTab {
.setPlaceholder('ghb-15457498545647987987112184')
.setValue(this.plugin.settings.GhToken)
.onChange(async (value) => {
this.plugin.settings.GhToken = value.trim()
await this.plugin.saveSettings()
this.plugin.settings.GhToken = value.trim();
await this.plugin.saveSettings();
})
)
containerEl.createEl('h3', { text: 'Sharing Settings' })

containerEl.createEl('h2', {text: 'Download configuration'})

containerEl.createEl('h5', {text: 'Folder reception settings'})
new Setting(this.containerEl)
.setName('Folder Reception settings')
.setDesc('Choose between a fixed folder or the value of a frontmatter key.')
.addDropdown((dropDown) => {
dropDown
.addOptions({
fixedFolder : 'Fixed Folder',
yamlFrontmatter: 'YAML frontmatter'
})
.setValue(this.plugin.settings.downloadedFolder)
.onChange(async(value: string)=>{
this.plugin.settings.downloadedFolder=value;
if (value == 'yamlFrontmatter') {
showSettings(frontmatterKeySettings);
showSettings(rootFolderSettings);
} else {
hideSettings(frontmatterKeySettings);
hideSettings(rootFolderSettings);
}
await this.plugin.saveSettings();
});
});


new Setting(this.containerEl)
.setName('Default Folder')
.setDesc('Set the default reception folder')
.addText((text) => {
text
.setPlaceholder('docs')
.setValue(this.plugin.settings.folderDefaultName)
.onChange(async (value) => {
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();
});
});

if (this.plugin.settings.downloadedFolder == 'yamlFrontmatter') {
showSettings(frontmatterKeySettings);
showSettings(rootFolderSettings);
} else {
hideSettings(frontmatterKeySettings);
hideSettings(rootFolderSettings);
}

containerEl.createEl('h5', {text: 'Workflow dispatches'})
new Setting(containerEl)
.setName('Name')
.setDesc('If you want to activate a github action when the plugin push the file, set the name.')
.addText((text)=>{
text
.setPlaceholder('ci')
.setValue(this.plugin.settings.workflowName)
.onChange(async(value)=> {
this.plugin.settings.workflowName = value.trim() +'.yml';
await this.plugin.saveSettings();
});
});

containerEl.createEl('h5', {text: 'Embedded files'})
new Setting(containerEl)
.setName('Transfer image')
.setDesc('Send image linked to a file in github')
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.transfertEmbeded)
.onChange(async (value) => {
this.plugin.settings.transfertEmbeded = value;
value ? showSettings(settingsDefaultImage) : hideSettings(settingsDefaultImage);
await this.plugin.saveSettings();
});
});

const settingsDefaultImage = new Setting(containerEl)
.setName('Default image folder')
.setDesc('To use a folder different from default')
.addText((text)=>{
text
.setPlaceholder('docs/images')
.setValue(this.plugin.settings.defaultImageFolder)
.onChange(async(value)=>{
this.plugin.settings.defaultImageFolder = value.replace('/', '');
await this.plugin.saveSettings();
});
});

this.plugin.settings.transfertEmbeded ? showSettings(settingsDefaultImage) : hideSettings(settingsDefaultImage);

containerEl.createEl('h1', { text: 'Plugin Settings' })
new Setting(containerEl)
.setName('Share Key')
.setDesc('The frontmatter key to publish your file on the website.')
Expand Down Expand Up @@ -130,56 +268,5 @@ export class MkdocsSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings()
})
)

containerEl.createEl('h3', { text: 'OBS2MK settings' })

new Setting(containerEl)
.setName('Category Key')
.setDesc('The frontmatter key to set the category of your file.')
.addText((text) =>
text
.setPlaceholder('category')
.setValue(this.plugin.settings.categoryKey)
.onChange(async (value) => {
this.plugin.settings.categoryKey = value.trim()
await this.plugin.saveSettings()
})
)

new Setting(containerEl)
.setName('Default category')
.setDesc('The default folder where you note will be published.')
.addText((text) =>
text
.setPlaceholder('Notes')
.setValue(this.plugin.settings.categoryDefault)
.onChange(async (value) => {
this.plugin.settings.categoryDefault = value.trim()
await this.plugin.saveSettings()
})
)

const desc_index = document.createDocumentFragment()
desc_index.createEl('span', null, (span) => {
span.innerText = 'The index key is used for the citation of the folder note. See '
span.createEl('a', null, (link) => {
link.innerText = 'documentation'
link.href = 'https://mara-li.github.io/mkdocs_obsidian_template/documentation/blog%20customization/#folder-note'
})
span.innerText = ' for more information.'
})

new Setting(containerEl)
.setName('Index Folder Note Key')
.setDesc(desc_index)
.addText((text) =>
text
.setPlaceholder('(i)')
.setValue(this.plugin.settings.indexFolder)
.onChange(async (value) => {
this.plugin.settings.indexFolder = value.trim()
await this.plugin.saveSettings()
})
)
}
}
Loading

0 comments on commit 837ef71

Please sign in to comment.