diff --git a/mkdocsPublisher/main.ts b/mkdocsPublisher/main.ts index 70d05a4f..fffa8613 100644 --- a/mkdocsPublisher/main.ts +++ b/mkdocsPublisher/main.ts @@ -1,20 +1,20 @@ import { Notice, Plugin, TFile } from "obsidian"; import { - mkdocsSettingsTab, - mkdocsPublicationSettings, + MkdocsSettingsTab, + MkdocsPublicationSettings, DEFAULT_SETTINGS, } from "./settings"; import { ShareStatusBar } from "./utils/status_bar"; import MkdocsPublish from "./utils/publication"; import { disablePublish } from "./utils/utils"; -export default class mkdocsPublication extends Plugin { - settings: mkdocsPublicationSettings; +export default class MkdocsPublication extends Plugin { + settings: MkdocsPublicationSettings; async onload() { console.log("Mkdocs Publication loaded"); await this.loadSettings(); - this.addSettingTab(new mkdocsSettingsTab(this.app, this)); + this.addSettingTab(new MkdocsSettingsTab(this.app, this)); this.registerEvent( this.app.workspace.on("file-menu", (menu, file: TFile) => { @@ -40,7 +40,7 @@ export default class mkdocsPublication extends Plugin { const publishSuccess = await publish.publish(file, true); if (publishSuccess) { - await publish.workflow_gestion(); + await publish.workflowGestion(); new Notice( "Successfully published " + file.basename + @@ -83,7 +83,7 @@ export default class mkdocsPublication extends Plugin { const publishSuccess = await publish.publish(view.file, true); if (publishSuccess) { - await publish.workflow_gestion(); + await publish.workflowGestion(); new Notice( "Successfully published " + view.file.basename + @@ -127,7 +127,7 @@ export default class mkdocsPublication extends Plugin { true ); if (publishSuccess) { - publishFile.workflow_gestion(); + publishFile.workflowGestion(); new Notice( "Successfully published " + currentFile.basename + @@ -196,7 +196,7 @@ export default class mkdocsPublication extends Plugin { publishedFiles.length - errorCount } notes to mkdocs.` ); - await publish.workflow_gestion(); + await publish.workflowGestion(); } } catch (e) { // statusBarItems.remove(); diff --git a/mkdocsPublisher/settings.ts b/mkdocsPublisher/settings.ts index 85845365..de5e642f 100644 --- a/mkdocsPublisher/settings.ts +++ b/mkdocsPublisher/settings.ts @@ -1,7 +1,7 @@ -import { App, PluginSettingTab, Setting } from 'obsidian' -import mkdocsPublication from './main' +import {App, PluginSettingTab, Setting} from 'obsidian' +import MkdocsPublication from './main' -export interface mkdocsPublicationSettings { +export interface MkdocsPublicationSettings { githubRepo: string; githubName: string; GhToken: string; @@ -14,171 +14,172 @@ export interface mkdocsPublicationSettings { indexFolder: string; } -export const DEFAULT_SETTINGS: mkdocsPublicationSettings = { - githubRepo: '', - githubName: '', - GhToken: '', - shareKey: 'share', - ExcludedFolder: '', - fileMenu: false, - editorMenu: false, - categoryKey: 'category', - categoryDefault: 'notes', - indexFolder: '(i)' +export const DEFAULT_SETTINGS: MkdocsPublicationSettings = { + githubRepo: '', + githubName: '', + GhToken: '', + shareKey: 'share', + ExcludedFolder: '', + fileMenu: false, + editorMenu: false, + categoryKey: 'category', + categoryDefault: 'notes', + indexFolder: '(i)' } -export class mkdocsSettingsTab extends PluginSettingTab { - plugin: mkdocsPublication; - constructor (app: App, plugin: mkdocsPublication) { - super(app, plugin) - this.plugin = plugin +export class MkdocsSettingsTab extends PluginSettingTab { + plugin: MkdocsPublication; + + constructor(app: App, plugin: MkdocsPublication) { + super(app, plugin) + this.plugin = plugin } - display (): any { - const { containerEl } = this - containerEl.empty() - containerEl.createEl('h1', { text: 'Mkdocs Publication Settings' }) - new Setting(containerEl) - .setName('Repo Name') - .setDesc('The name of the repository where you store your blog.') - .addText((text) => - text - .setPlaceholder('mkdocs-template') - .setValue(this.plugin.settings.githubRepo) - .onChange(async (value) => { - this.plugin.settings.githubRepo = value - await this.plugin.saveSettings() - }) - ) - new Setting(containerEl) - .setName('Github Username') - .setDesc('Your github username.') - .addText((text) => - text - .setPlaceholder('Github-username') - .setValue(this.plugin.settings.githubName) - .onChange(async (value) => { - this.plugin.settings.githubName = value - await this.plugin.saveSettings() - }) - ) - const desc_ghToken = document.createDocumentFragment() - desc_ghToken.createEl('span', null, (span) => { - span.innerText = 'A github token with repository permission. You can generate it ' - span.createEl('a', null, (link) => { - link.innerText = 'here' - link.href = 'https://github.com/settings/tokens/new?scopes=repo,workflow' - }) - }) - new Setting(containerEl) - .setName('Github Token') - .setDesc(desc_ghToken) - .addText((text) => - text - .setPlaceholder('ghb-15457498545647987987112184') - .setValue(this.plugin.settings.GhToken) - .onChange(async (value) => { - this.plugin.settings.GhToken = value - await this.plugin.saveSettings() - }) - ) - containerEl.createEl('h3', { text: 'Sharing Settings' }) - new Setting(containerEl) - .setName('Share Key') - .setDesc('The frontmatter key to publish your file on the website.') - .addText((text) => - text - .setPlaceholder('share') - .setValue(this.plugin.settings.shareKey) - .onChange(async (value) => { - this.plugin.settings.shareKey = value - await this.plugin.saveSettings() - }) - ) - new Setting(containerEl) - .setName('Excluded Folder') - .setDesc('Never publish file in these folder, regardless of the share key. Separate folder name by comma.') - .addTextArea((textArea) => - textArea - .setPlaceholder('_assets, Archive') - .setValue(this.plugin.settings.ExcludedFolder) - .onChange(async (value) => { - this.plugin.settings.ExcludedFolder = value - 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() - }) - ) - new Setting(containerEl) - .setName('Editor Menu') - .setDesc('Add a sharing commands in the right-click menu') - .addToggle((toggle) => - toggle - .setValue(this.plugin.settings.editorMenu) - .onChange(async (value) => { - this.plugin.settings.editorMenu = value - await this.plugin.saveSettings() - }) - ) + display(): void { + const {containerEl} = this + containerEl.empty() + containerEl.createEl('h1', {text: 'Mkdocs Publication Settings'}) + new Setting(containerEl) + .setName('Repo Name') + .setDesc('The name of the repository where you store your blog.') + .addText((text) => + text + .setPlaceholder('mkdocs-template') + .setValue(this.plugin.settings.githubRepo) + .onChange(async (value) => { + this.plugin.settings.githubRepo = value + await this.plugin.saveSettings() + }) + ) + new Setting(containerEl) + .setName('Github Username') + .setDesc('Your github username.') + .addText((text) => + text + .setPlaceholder('Github-username') + .setValue(this.plugin.settings.githubName) + .onChange(async (value) => { + this.plugin.settings.githubName = value + await this.plugin.saveSettings() + }) + ) + const desc_ghToken = document.createDocumentFragment() + desc_ghToken.createEl('span', null, (span) => { + span.innerText = 'A github token with repository permission. You can generate it ' + span.createEl('a', null, (link) => { + link.innerText = 'here' + link.href = 'https://github.com/settings/tokens/new?scopes=repo,workflow' + }) + }) + new Setting(containerEl) + .setName('Github Token') + .setDesc(desc_ghToken) + .addText((text) => + text + .setPlaceholder('ghb-15457498545647987987112184') + .setValue(this.plugin.settings.GhToken) + .onChange(async (value) => { + this.plugin.settings.GhToken = value + await this.plugin.saveSettings() + }) + ) + containerEl.createEl('h3', { text: 'Sharing Settings' }) + new Setting(containerEl) + .setName('Share Key') + .setDesc('The frontmatter key to publish your file on the website.') + .addText((text) => + text + .setPlaceholder('share') + .setValue(this.plugin.settings.shareKey) + .onChange(async (value) => { + this.plugin.settings.shareKey = value + await this.plugin.saveSettings() + }) + ) + new Setting(containerEl) + .setName('Excluded Folder') + .setDesc('Never publish file in these folder, regardless of the share key. Separate folder name by comma.') + .addTextArea((textArea) => + textArea + .setPlaceholder('_assets, Archive') + .setValue(this.plugin.settings.ExcludedFolder) + .onChange(async (value) => { + this.plugin.settings.ExcludedFolder = value + 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() + }) + ) + new Setting(containerEl) + .setName('Editor Menu') + .setDesc('Add a sharing commands in the right-click menu') + .addToggle((toggle) => + toggle + .setValue(this.plugin.settings.editorMenu) + .onChange(async (value) => { + this.plugin.settings.editorMenu = value + await this.plugin.saveSettings() + }) + ) - containerEl.createEl('h3', { text: 'OBS2MK settings' }) + 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 - await this.plugin.saveSettings() - }) - ) + 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 + 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 - 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 + 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.' - }) + 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 - await this.plugin.saveSettings() - }) - ) + 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 + await this.plugin.saveSettings() + }) + ) } } diff --git a/mkdocsPublisher/utils/publication.ts b/mkdocsPublisher/utils/publication.ts index 4047bb8c..a8847c0e 100644 --- a/mkdocsPublisher/utils/publication.ts +++ b/mkdocsPublisher/utils/publication.ts @@ -1,7 +1,7 @@ // Credit : https://github.com/oleeskild/obsidian-digital-garden @oleeskild import {MetadataCache, Notice, TFile, Vault} from 'obsidian' -import {mkdocsPublicationSettings} from '../settings' +import {MkdocsPublicationSettings} from '../settings' import {Octokit} from '@octokit/core' import {arrayBufferToBase64} from './utils' import {Base64} from 'js-base64' @@ -9,9 +9,9 @@ import {Base64} from 'js-base64' export default class MkdocsPublish { vault: Vault; metadataCache: MetadataCache; - settings: mkdocsPublicationSettings; + settings: MkdocsPublicationSettings; - constructor(vault: Vault, metadataCache: MetadataCache, settings: mkdocsPublicationSettings) { + constructor(vault: Vault, metadataCache: MetadataCache, settings: MkdocsPublicationSettings) { this.vault = vault this.metadataCache = metadataCache this.settings = settings @@ -52,10 +52,10 @@ export default class MkdocsPublish { } checkExcludedFolder (file: TFile) { - const excluded_folder = this.settings.ExcludedFolder.split(',').filter(x=>x!='') - if (excluded_folder.length > 0) { - for (let i = 0; i < excluded_folder.length; i++) { - if (file.path.contains(excluded_folder[i].trim())) { + const excludedFolder = this.settings.ExcludedFolder.split(',').filter(x=>x!='') + if (excludedFolder.length > 0) { + for (let i = 0; i < excludedFolder.length; i++) { + if (file.path.contains(excludedFolder[i].trim())) { return true } } @@ -64,17 +64,17 @@ export default class MkdocsPublish { } async publish (file: TFile, one_file = false) { - const sharedkey = this.settings.shareKey + const sharedKey = this.settings.shareKey const frontmatter = this.metadataCache.getCache(file.path).frontmatter - if (!frontmatter || !frontmatter[sharedkey] || this.checkExcludedFolder(file)) { + if (!frontmatter || !frontmatter[sharedKey] || this.checkExcludedFolder(file)) { return false } try { const text = await this.vault.cachedRead(file) - const linked_image = this.getLinkedImage(file) + const linkedImage = this.getLinkedImage(file) await this.uploadText(file.path, text, file.name) - if (linked_image.length > 0) { - for (const image of linked_image) { + if (linkedImage.length > 0) { + for (const image of linkedImage) { await this.uploadImage(image) } } @@ -152,7 +152,7 @@ export default class MkdocsPublish { } } - async workflow_gestion () { + async workflowGestion () { const octokit = new Octokit({ auth: this.settings.GhToken }) diff --git a/mkdocsPublisher/utils/utils.ts b/mkdocsPublisher/utils/utils.ts index 059d1afe..cd3c967f 100644 --- a/mkdocsPublisher/utils/utils.ts +++ b/mkdocsPublisher/utils/utils.ts @@ -3,7 +3,7 @@ import { TFile } from 'obsidian' import { Base64 } from 'js-base64' -import { mkdocsPublicationSettings } from '../settings' +import { MkdocsPublicationSettings } from '../settings' function arrayBufferToBase64 (buffer: ArrayBuffer) { let binary = '' @@ -15,15 +15,15 @@ function arrayBufferToBase64 (buffer: ArrayBuffer) { return Base64.btoa(binary) } -function disablePublish (app: App, settings: mkdocsPublicationSettings, file:TFile) { +function disablePublish (app: App, settings: MkdocsPublicationSettings, file:TFile) { const fileCache = app.metadataCache.getFileCache(file) const meta = fileCache?.frontmatter - const folder_list = settings.ExcludedFolder.split(',').filter(x => x!=='') + const folderList = settings.ExcludedFolder.split(',').filter(x => x!=='') if (meta === undefined) { return false - } else if (folder_list.length > 0) { - for (let i = 0; i < folder_list.length; i++) { - if (file.path.contains(folder_list[i].trim())) { + } else if (folderList.length > 0) { + for (let i = 0; i < folderList.length; i++) { + if (file.path.contains(folderList[i].trim())) { return false } }